如何自定义错误消息被覆盖的密码控制器?
- 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派生的自定义注册控制器,而不适用于自定义密码控制器.
有什么解决方案吗?