Module: CodyRobbins::SaveChangesTo::InstanceMethods
- Defined in:
- lib/cody_robbins/save_changes_to/instance_methods.rb
Instance Method Summary collapse
-
#save_changes_to(name) ⇒ boolean
Updates the attributes of an instance of a model in an appropriately named instance variable in the controller with the attributes in
params
corresponding to the model name.
Instance Method Details
#save_changes_to(name) ⇒ boolean
Updates the attributes of an instance of a model in an appropriately named instance variable in the controller with the attributes in params
corresponding to the model name.
- You pass the name of the model to update to the method.
- The key in
params
assumed to contain the attributes of the model is extrapolated from the model name. For example, if the model isUser
then this key would be:user
. - The instance variable that is updated is assumed to be named according to the model. For example, if the model is
User
then the instance variable will be@user
.
26 27 28 29 30 31 |
# File 'lib/cody_robbins/save_changes_to/instance_methods.rb', line 26 def save_changes_to(name) model = instance_variable(name) attributes = params[name] model.update_attributes(attributes) end |