Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override validation with Rails + Devise

I'm trying override the :message validates_presence_of email and password, but I can not. How to I solve this?

like image 919
Diego Dias Avatar asked Feb 25 '12 23:02

Diego Dias


2 Answers

The source code shows another route: you can override some methods to determine whether they are needed:

  def password_required?
    !persisted? || !password.nil? || !password_confirmation.nil?
  end

  def email_required?
    true
  end

Put those functions in your user model, and change them as needed.

like image 139
DGM Avatar answered Nov 02 '22 06:11

DGM


I describe here how to customize your devise validations: http://jessewolgamott.com/blog/2011/12/08/the-one-where-devise-validations-are-customized/

You'll remove :validatable and replace/customize the rest

like image 6
Jesse Wolgamott Avatar answered Nov 02 '22 04:11

Jesse Wolgamott