开发者

Is that possible to get the file name in Paperclip validation message?

开发者 https://www.devze.com 2023-03-15 06:25 出处:网络
I use Paperclip 2.3.11 in my Rails 3 application, and have the following validation: validates_attachment_size :asset, :less_than => 2.megabytes,

I use Paperclip 2.3.11 in my Rails 3 application, and have the following validation:

validates_attachment_size :asset, :less_than => 2.megabytes, 
      开发者_StackOverflow中文版                    :message => "bigger than 2MB"

Is that possible to include the original file name in the message, so it will look like:

my_file.jpg bigger than 2MB


I think you ought to be able to pass in a lambda for :message, e.g.:

validates_attachment_size :asset, :less_than => 2.megabytes, 
                          :message => lambda {|asset| "#{asset.file_name} bigger than 2MB" }
0

精彩评论

暂无评论...
验证码 换一张
取 消