When defining a virtual setter method that relies on another method to be set up, it seems that the order of the attributes specified in the hashing matters. Is there a way around this while the mass assignment attributes are still there?
https://gist.github.com/3629539
EDIT
A condition in real code, not shown in the example, checks for the presence of a related object. If the object exists, set the value. If not, ignore the passed value. However, I also use accepts_nested_attributes_for. Thus, an attribute hash may contain attributes for association. In this case, the object will exist.
{:name => 'Fred', :nested_attributes => {:color => 'red'}}
The name will not be set because the model will not exist.
{:nested_attributes => {:color => 'red'}, :name => 'Fred'}
accepts_nested_attributes_for will create a nested instance and then set the attributes. When the name is set, an instance will exist and the nested attribute will be set.
source share