Smarter paperclip validations

早过忘川 提交于 2019-11-28 16:54:09
Leonardo Meira
validates_attachment_size :photo, :less_than => 1.megabyte, 
  :unless => Proc.new { |imports| imports.photo_file_name.blank? }

I think you can do it other way. Don't mess with validations. You probably have something like this in your form:

<%= f.error_messages %>

You can remove it and write your own helper to display error messages. Errors are stored in hash:

@photo.errors

Or if you want to get to them through form builder:

f.object.errors
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!