Cleaning up Paperclip error messages

前端 未结 2 2037
醉梦人生
醉梦人生 2021-01-01 05:48

Okay, so i\'ve got paperclip working, and I\'m trying to use the built in validator to make sure that the file uploaded

  1. Is an image
  2. Is not too big
2条回答
  •  轮回少年
    2021-01-01 06:26

    Obviously you solved this for yourself a long time ago, but for anyone who is looking for the answer, there is actually a way to do it within the provided validation.

    Simple add your message like so:

    validates_attachment :avatar,
    :content_type => { :content_type => /image/, :message => "Avatar must be an image" },
    :size => { :in => 0..2.megabytes, :message => "Avatar must be less than 2 megabytes in size" }
    

提交回复
热议问题