validate and update single attribute rails

后端 未结 5 1549
旧巷少年郎
旧巷少年郎 2021-02-08 22:55

I have the following in my user model

attr_accessible :avatar, :email

validates_presence_of :email
has_attached_file :avatar # paperclip

validates_attachment_s         


        
5条回答
  •  清歌不尽
    2021-02-08 23:22

    Have you tried putting a condition on the validates_presence_of :email ?

    http://ar.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000083

    Configuration options:

    if - Specifies a method, proc or string to call to determine if the validation should occur (e.g. :if => :allow_validation, or :if => Proc.new { |user| user.signup_step > 2 }). The method, proc or string should return or evaluate to a true or false value.

    unless - Specifies a method, proc or string to call to determine if the validation should not occur (e.g. :unless => :skip_validation, or :unless => Proc.new { |user| user.signup_step <= 2 }). The method, proc or string should return or evaluate to a true or false value.

提交回复
热议问题