ruby-on-rails – 如何在密码更改时覆盖设计错误消息
发布时间:2020-12-16 20:30:47 所属栏目:百科 来源:网络整理
导读:如何自定义错误消息被覆盖的密码控制器? class PasswordsController Devise::PasswordsController def create self.resource = resource_class.send_reset_password_instructions(params[resource_name]) if resource.errors.empty? set_flash_message(:not
如何自定义错误消息被覆盖的密码控制器?
class PasswordsController < Devise::PasswordsController def create self.resource = resource_class.send_reset_password_instructions(params[resource_name]) if resource.errors.empty? set_flash_message(:notice,:send_instructions) if is_navigational_format? respond_with resource,:location => home_path else binding.pry flash[:devise_password_error] = (resource.errors.map do |key,value| value.capitalize end).flatten.join('|') redirect_to home_path and return end end def edit self.resource = resource_class.new resource.reset_password_token = params[:reset_password_token] end end resource.errors可用于此方法,但它包含默认消息,如电子邮件未找到,电子邮件不能为空.我需要定制这个消息.我试图从我的用户模型中删除:可验证,并添加自定义验证器,但这仅适用于我从Devise :: RegistrationsController派生的自定义注册控制器,而不适用于自定义密码控制器. 有什么解决方案吗? 解决方法
答案是修改config / locales / devise.en.yml,但是您必须添加设置,默认情况下不存在.
en: activerecord: errors: models: user: attributes: password: confirmation: "does not match" too_short: "is too short (minimum is %{count} characters)" 对于这样的信用给了Vimsha,对我来说几乎相同的question. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |