I am using strong_params and trying to pass an object. I have two questions.
- How do I know which attribute is causing the problem?
- What am I missing in the code below?
Let's start with the error, the magazine is not telling me anything.
ActiveModel::ForbiddenAttributesError in JobsController
Just for a giggle, here is a magazine that I don't see very useful:
Started POST "/jobs" for 127.0.0.1 at 2013-12-17 22:03:59 +0000 Processing by JobsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"Ohq4lVqPVMpjzbZwCfJNYBL78TAcoC0WZLSmpCzMD3k=", "job"=>{"job_title"=>"Junior Rails Developer", "job_description"=>"A new position getig nsomethfins lansnana", "languages"=>["", "Rails", "Ruby"], "country_code"=>"AO", "job_type"=>"Full-Time", "job_salary"=>"30000", "job_level"=>"Junior"}, "commit"=>"Create Job"} User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1 Completed 500 Internal Server Error in 8ms ActiveModel::ForbiddenAttributesError (ActiveModel::ForbiddenAttributesError):
It makes sense, but then if I look at my creation:
def create binding.pry @job = Job.new(job_params) respond_to do |format| if @job.save format.html { redirect_to @job, notice: 'Job was successfully created.' } format.json { render action: 'show', status: :created, location: @job } else format.html { render action: 'new' } format.json { render json: @job.errors, status: :unprocessable_entity } end end end
Strong_params:
def job_params params.require(:job).permit(:job_title, :job_level, :job_description, :job_salary, :country_code, :job_type, :state, :languages => []) end
I'm mostly interested in learning how to find out where the problem is for the future, as it looks like a needle in a hay bug.