【发布时间】:2014-04-26 11:02:25
【问题描述】:
我有 2 个模型:会议和会谈。会议有_many会谈和
accepts_nested_attributes_for :talks, :allow_destroy => true
我发布的参数看起来像这样:
{"id"=>"2", "name"=>"rails4444", "tags"=>"ruby, rails, backbone, javascript", "date"=>"2014-02-22", "organizer"=>"BackboneMeetupGroup", "description"=>"conference with cool speakers", "talks"=>{"title"=>"fdsf", "video_url"=>"fdsf"},
我将谈话设置为应该在数据库中创建的位置。
我的 html 看起来像这样:
<input type="text" name="talks[title]" placeholder="Talk Title" />
<input type="text" name="talks[video_url]" placeholder="url" />
当我用谈话更新我的会议模型时,它给了我一个错误:
ActiveRecord::AssociationTypeMismatch(预期对话(#70154003251480),得到数组(#70154000241560)): app/controllers/conferences_controller.rb:25:in `update'
我的控制器看起来像这样:
def update
@single = Conference.find params[:id]
if @single.update_attributes conference_params
render "conferences/show"
else
respond_with @single
end
end
def conference_params
params.permit(:name, :tags, :date, :organizer, :description, :place, :talks => [:conference_id, :id, :title, :video_url])
end
为什么会出现 ActiveRecord::AssociationTypeMismatch 错误,我该如何解决?
【问题讨论】:
标签: ruby-on-rails ruby json activerecord ruby-on-rails-4