Real problem with an existing webapp which has been working for the last couple of years...
ActiveRecord::AssociationTypeMismatch (Note(#23706868500220) expected, got String(#237068449开发者_运维百科96600)):
app/controllers/jobs_controller.rb:56:in `new'
app/controllers/jobs_controller.rb:56:in `create'
Line 56 of jobs_controller.rb:
@jobs = Jobs.new(params[:jobs])
Parameters from Console:
Parameters: {
"label" => { "userid" => "332" },
"jobs" => {
"sub" => "7",
"notes" => "Test Note Information",
"master" => "1",
"user_id" => "332",
"file" => "Screen shot 2010-02-19 at 13.33.19.png",
"ref" => "12345",
"jobtitle"=> "Test Job",
"status" => "0"
},
"x" => "111",
"y" => "6",
"id" => "newjob"
}
Anyone able to advise?
Cheers,
Carl
It would seem like you have a declaration in your Job model that is causing grief:
class Job < ActiveRecord::Base
has_many :notes
end
When you try and assign to an association like that, you will get conflict. You need to convert the textual note into a proper record before assigning it.
You may be able to do something like this:
params[:jobs][:notes] = [ Note.new(:note => params[:jobs][:notes]) ]
The actual parameter names will depend on your Note model.
You can also investigate accepts_nested_attributes_for but that could be a separate question.
精彩评论