我想自定义已由设备
注册的用户错误消息我的注册类别:
class Usuarios::RegistrationsController < Devise::RegistrationsController
def new
super do |usuario|
redirect_to ""
end
end
def create
super do |usuario|
usuario.prevent_login = true
end
end
def build_resource(hash=nil)
super
set attributes
end
答案 0 :(得分:0)
您可以通过在帮助程序中添加devise_helper.rb来完成此操作。这将覆盖默认的Devise错误消息
module DeviseHelper
def devise_error_messages!
return "" unless devise_error_messages?
messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
sentence = I18n.t("errors.messages.not_saved",
:count => resource.errors.count,
:resource => resource.class.model_name.human.downcase)
html = <<-HTML
<div id="error_explanation">
<h2>#{sentence}</h2>
<ul>#{messages}</ul>
</div>
HTML
html.html_safe
end
def devise_error_messages?
!resource.errors.empty?
end
end