problems with build params for accepts_nested_attributes_for

Posted by holden on Stack Overflow See other posts from Stack Overflow or by holden
Published on 2010-04-27T13:48:59Z Indexed on 2010/04/27 13:53 UTC
Read the original article Hit count: 403

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?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about nested-attributes