Smarter paperclip validations

前端 未结 2 1804
迷失自我
迷失自我 2020-12-13 01:11

I\'m using paperclip in a rails app and have the following three validations in my model

validates_attachment_presence :photo                    
validates_a         


        
相关标签:
2条回答
  • 2020-12-13 01:39
    validates_attachment_size :photo, :less_than => 1.megabyte, 
      :unless => Proc.new { |imports| imports.photo_file_name.blank? }
    
    0 讨论(0)
  • 2020-12-13 01:47

    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
    
    0 讨论(0)
提交回复
热议问题