以前にネストされた属性と form_for を使用したことがありますが、単純なものが欠けています。これが私のモデルです...
スキル.rb
class Skill < ActiveRecord::Base
belongs_to :tag
attr_accessible :tag_id, :user_id, :weight
end
タグ.rb
class Tag < ActiveRecord::Base
has_many :skills
attr_accessible :name, :skills_attributes
accepts_nested_attributes_for :skills
end
アプリ/ビュー/タグ/_form.html.erb
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<%= f.fields_for :skill do |s| %>
<%= s.label :weight %><br />
<%= s.text_field :weight %>
<% end %>
両方のモデルのパラメーターは正常に渡されていますが、コンソールに一括割り当てエラーが表示されます...
Started POST "/tags" for 127.0.0.1 at 2013-07-26 10:13:51 -0400
Processing by TagsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"yofQhmgOyNHvnws/Lg+BoS4TqeTwPdyQjQbLXotnEzI=", "tag"=>{"name"=>"test", "skill"=>{"weight"=>"ee"}}, "commit"=>"Create Tag"}
Completed 500 Internal Server Error in 1ms
ActiveModel::MassAssignmentSecurity::Error (Can't mass-assign protected attributes: skill):
app/controllers/tags_controller.rb:43:in `new'
app/controllers/tags_controller.rb:43:in `create'
どんな助けでも大歓迎です!