Is there a way I can know what attributes are updated in my model? I only want to do a validation on a user when a certain attribute was posted. This would actually be the hash that is sent via the params
eg:
@user.update_attributes(params[:user])
Thanks.
This is available within the ActiveRecord::Dirty module, which is included by default.
The
changedmethod will give you a list of attributes with unsaved changes. Thechangesmethod will give you a hash of unsaved changes, where the keys are the attribute names and the values are an array consisting of the original and new value.For example: