Rails Paperclip: update vs. update_attributes

By the way, #update_attributes gonna be deprecated from Rails 6 (though this is not released yet)

please have a look at

  • https://github.com/rails/rails/pull/31998
  • https://github.com/rails/rails/commit/5645149d3a27054450bd1130ff5715504638a5f5

for more details.


ActiveRecord.update has a behavior that may be throwing you off:

Updates an object (or multiple objects) and saves it to the database, if validations pass. The resulting object is returned whether the object was saved successfully to the database or not. http://apidock.com/rails/ActiveRecord/Base/update/class

However the update_attributes will just return false.

Both of these use Model-level validations and so both should save or not save equally. However, the return values will be different.

As @RoaringStones pointed out, the solution is to use

user = User.update(user.id, user_avatar_params)

For what it's worth, as of Rails 4.0.2, #update returns false if the update failed, not simply the object which the update failed for. Of further note, #update_attributes is simply an alias of #update now.