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.
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.
…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.
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.