How do I add a value to params coming from a form before it is saved? I have a value passed in the params which I use to do a find in a related table. All works fine. But when I want to add that into the current save – current table - I''m lost. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
infoarts-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Dec-10 22:18 UTC
Re: Add value to params before save
I''m not entirely clear what you are trying to achieve but why not set the attribute directly then save? You don''t need to add it to the params hash, but just to the object itself (if I understand your question correctly). @my_object.attribute = value if @my_object.save # do something here else # do something else end You might want to also check out the ''update'' and ''update_attributes'' methods as well. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
infoarts-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Dec-10 22:23 UTC
Re: Add value to params before save
...and the ''update_attribute'' method as well. update_attribute and update_attributes allow you to set the attribute(s) and save the record in one step. So you might be using the params hash to populate the bulk of the object''s attributes and then adding in extra attribute(s) with these methods. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
unknown wrote:> ...and the ''update_attribute'' method as well. > > update_attribute and update_attributes allow you to set the > attribute(s) and save the record in one step. So you might be using > the params hash to populate the bulk of the object''s attributes and > then adding in extra attribute(s) with these methods.Attribute! Thanks. :-) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---