I am using Ruby on Rails 3.1.0 and the Paperclip gem. I would like to change the normal behavior to validate and add error messages to a class object.
That is, an invalid instance of a User
class is (the :avatar_file_size
error is related to the Paperclip gem)
#<ActiveModel::Errors:0x0000010166cfb8 @base=#<User id: 1, firstname: "Sample firstname", lastname: "Sample lastname", avatar_file_name: "avatar_file.jpg",
...>, @messages={:avatar_file_size=>["is too big"]}>
I would like to have the following output (note that the :avatar_file_size
error-hash key is changed to :avatar
):
#<ActiveModel::Errors:0x0000010166cfb8 @base=#<User id: 1, firstname: "Sample firstname", lastname: "Sample lastname", avatar_file_name: "avatar_file.jpg",
...>, @messages={:avatar=>["is too big"]}>
In few words, what I would like to do is to change the error-hash key related to the error message generated by the Paperclip gem.
How can I do that?
Maybe it is possible to do that directly in the validates
method present in the User
model that at this time is:
validates_attachment_size :avatar,
:less_than => 4.megabytes,
:message => "is too big"