I have implemented nested attributes using railscasts and I am using devise in application. Here is the simple structure.
I have two model ie Group and Invite.
Group Model has
accepts_nested_attributes_for :invites, :reject_if => lambda { |a| a[:email].blank? }, :allow_destroy => true
and it works perfectly fine.
here is the hash of the parameters.
Parameters: {"utf8"=>"✓", "authenticity_token"=>"uI0HmJrIE9Qh3pZW2qIJymeON/yjbFSgcH8bRx/x5Oo=", "group"=>{"name"=>"Test Group", "description"=>"", "invites_attributes"=>{"0"=>{"name"=>"Test User", "email"=>"test@example.com", "_destroy"=>"false"}}}, "commit"=>"Create Group"}
Now the problem is I want to store invitee user_id in invites table, But I can access current_user in invite model. So how can I modify the hash in order to save current_user id in invite model.
Basically things will be easy if my hash parameters is:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"uI0HmJrIE9Qh3pZW2qIJymeON/yjbFSgcH8bRx/x5Oo=", "group"=>{"name"=>"Test Group", "description"=>"", "invites_attributes"=>{"0"=>{"name"=>"Test User", "email"=>"test@example.com", "_destroy"=>"false", :invited_by => "1" }}}, "commit"=>"Create Group"}
How can I modify hash at controller end? or is there is better way to achieve this.
Maybe you could try using
hidden_field.So, you may write something like this (based on the Railscasts):
From APIdock:
Ref: