rails 3 accepts nested attributes not working
I am trying to use nested attributes on my user model for settings so that I can edit the user info and the setting info in a single page. Here is my code:
User.rb
has_one :settings
accepts_nested_attributes_for :settings, :allow_destroy => true
attr_accessor :settings_attributes
views/users/registrations/edit.html.erb
<%= f.fields_for :settings do |s| %>
<p>
<%= s.label :newsletter %><br />
<%= s.check_box :newslet开发者_开发知识库ter %>
</p>
<% end %>
This seemingly works just fine, the form is displayed properly. However the attributes for the settings are not changed at all when I submit the form.
I am using Rails 3, and Devise created my user model. Perhaps I am missing something that needs to go in the controller model?
Most likely caused by using plural instead of singular for setting. Try changing to this:
model
has_one :setting
accepts_nested_attributes_for :setting, :allow_destroy => true
view
<%= f.fields_for :setting do |s| %>
What are you using the attr_accessor for?
精彩评论