0
votes

i am newbee want learn ruby on rails i learn this code from tutorial on youtube.

i stuck to find undefined method `description'.

Here my _form.html.hmal

Here my new.html.haml

Here my code jobs_controller.rb

class JobsController < ApplicationController before_action :find_job, only: [:show, :edit, :update, :destroy]

def index
    @jobs = Job.all.order("created_at DESC")
end

def show
end

def new
    @job = Job.new
end

def create
    @job = Job.new(jobs_params)

    if @job.save
        redirect_to @job
    else
        render "New"
    end
end

def edit
end

def update
end

def destroy #to delete
end

private
def jobs_params
    params.require(:job).permit(:title, :description, :company, :url)
end

def find_job
    @job = Job.find(params[:id])
end

end

3
Please post code snippets as text, not as images.Aleksei Matiushkin
You @job instance does not have description attribute. You need to add it through migration.zolter

3 Answers

0
votes

Description is not an attribute of Job model/table and still you are using it in your form_for that's why it's giving undefined method description.

0
votes

You haven't got a description on your job model. Run this command in your console:

rails g migration add_description_to_jobs description

'add_description_to_jobs' creates the migration file itself, and 'description' will create a string field 'description'. If you said 'description:integer' it would instead create it as an integer, but you won't need that in this instance.

0
votes

What I can see is you are using simple simple_form_for with @job, and in the code you have

f.input :description, label: "Job Description"

So this error means your @job object is not having "description" attribute, which you have used with f.input, please check for that.