how to overwrite authlogic validation messages in rails?
i'm using Rails Authlogic开发者_如何学编程 in my application. i want to overwrite validation messages. validates_length_of and validates_format_of are working but validates_presence_of is not working for both login and password.
can someone help me to fix this issue?
Add a locale language file config/locales/es.yml to locales then add something like this:
es:
authlogic:
error_messages:
login_blank: No puede estar en blanco
login_not_found: no es valido
login_invalid: "debe utilizar sólo letras, numeros, espacios, y .-_@ por favor."
consecutive_failed_logins_limit_exceeded: Consecutive failed logins limit exceeded, account is disabled.
email_invalid: debe ser similar a una dirección de correo electrónico.
password_blank: No puede estar en blanco
password_invalid: no es valido
not_active: Tu cuenta no está activo
not_confirmed: Su cuenta no se confirma
not_approved: "Tu cuenta no está aprobada"
no_authentication_details: Usted no proporcionó ningún detalle para la autenticación.
email_invalid: "No es valido"
Are the validations failing for your User
or UserSession
model? Or both?
For the User
model, ensure that you are calling acts_as_authentic
:
class User
acts_as_authentic
end
For the UserSession
model, ensure that you're inheriting from the Session
class:
class UserSession < Authlogic::Session::Base
end
As for customizing the error messages, you can use the i18n approach as detailed below. Or, for the User
model at least, you can do it in Ruby. See these Authlogic docs:
http://rdoc.info/github/binarylogic/authlogic/master/Authlogic/ActsAsAuthentic/Login/Config http://rdoc.info/github/binarylogic/authlogic/master/Authlogic/ActsAsAuthentic/Password/Config
In those docs, you'll notice some methods beginning with "merge." Those should do the trick for you.
I couldn't find anything equivalent for the Session
class. The comment in this Stack Overflow question suggests that it doesn't exist:
Custom validation messages for Session model in Authlogic
精彩评论