problems with build params for accepts_nested_attributes_for
- by holden
I'm trying to add the user_id to a nested attribute that gets built by a parent controller but it doesn't seem to have the desired effect?
Ie. I have a model called Place.rb which accepts_nested_attributes_for :reviews
The nested attribute works fine and I build it inside the Places controller like so...
@review = @place.reviews.build(:user_id => current_user.id)
I was previously adding the user thru the form, but would like to do it thru the controller so that it only adds the user_id on creation, as it might get updated by someone else and i don't want the update changing the user_id...
old way which works:
<%= e.label :content, "Review" %><br />
<%= e.text_area :content, :rows => 20, :class => 'jquery_ckeditor' %><br />
<%= e.hidden_field :user_id, :value => current_user.id %>
but thru the controller the build method with options has no effect? Any ideas? Can I not do this thru the build?