[devise] Help with customizing Devise validations (Rails 3)

1,953 vistas
Ir al primer mensaje no leído

ericindc

no leída,
1 may 2010, 9:51:19 a.m.1/5/2010
para Devise
What is the easiest way to customize the validation error (i.e. -
"Email can't be blank") messages displayed by Devise? I started to
remove the :validatable module in favor of my own validations, but how
do I get access to Devise's :password_required? method? Also is there
a way to customize the :devise_error_messages! helper method? Thanks.

Nat Budin

no leída,
29 jun 2010, 4:02:57 p.m.29/6/2010
para Devise
Not sure if you got an answer figured out to this one or not, but I
just ran into it myself, so I figured I'd post the answer I came
around to.

If you want to skip the password checks in validatable but keep the
rest of it, you can override the password_required? method like so:

class User < ActiveRecord::Base
devise :database_authenticatable, :validatable

protected
def password_required?
false
end
end

Or, if you want to allow no password to be set under certain
conditions (as I did, since I have a legacy_password_md5 field I fall
back to in some cases):

def password_required?
legacy_password_md5.blank? && super
end
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos