【发布时间】:2015-04-23 01:37:53
【问题描述】:
在我的模型用户中,我添加了以下验证问题是设计已经实现了自己的验证。如何覆盖 Devise 的验证
用户.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable and :timeoutable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
validates_presence_of :email, :message=>"email no puede estar vacio"
validates_presence_of :password, :message=>"password no puede estar vacio"
validates_presence_of :password_confirmation,:message=>"validate confirmation no puede estar vacio"
end
浏览器
Email can't be blank #validation of devise
Email email no puede estar vacio #my own validation
Password can't be blank #validation of devise
Password password no puede estar vacio #my own validation
Password confirmation validate confirmation no puede estar vacio
我遇到的其他问题是 rails 显示自定义消息之前的属性名称
Email email no puede estar vacio #my own validation #wrong
email no puede estar vacio #well
【问题讨论】:
-
如果您重写设计验证只是为了以西班牙语显示一条消息,我认为您做错了。您应该编写一个西班牙语言环境文件 es.yml 并翻译此文件中的设计错误消息 (github.com/plataformatec/devise/wiki/I18n)。使用 I18n.locale = :es 将语言环境设置为西班牙语
标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-4 devise