设计在身份validation失败期间不显示错误消息?

当设计中发生身份validation失败时,我期待闪存通知。 但在身份validation失败期间什么也得不到,只是页面刷新并保持静止。 我没有改变任何东西。 默认设计安装本身不会显示无效身份validation尝试的闪存错误。 我刚安装了一个设计作为gem的设计。 甚至不会改变生成的代码。
可能是因为某些浏览器的可比性问题。
但我得到其他手动介绍闪光消息其他工作。

关于什么可能被打破的任何建议。

我正在使用rails 3.0.1
*更新*

我收到了用户注册(注册)的失败消息,但没有登录失败消息的消息。有些关于此主题的google消息显示,对于注册,它预计: –
但是对于登录,它期望引用其他一些警报消息标记,但是没有得到我必须使用的警报标记的确切信息并且将使用???

请提供一些建议!!!
提前致谢。

经过一番大量的搜索/浏览,我找到了答案,
你必须在我们的application.html.erb文件中添加以下代码

<%- flash.each do |name, msg| -%> <%= content_tag :div, msg, :id => "flash_#{name}" if msg.is_a?(String) %> <%- end -%> 

添加之后,我能够看到sign_in失败警报消息:)。

不可否认,有点hacky,但我正在使用这个助手(app / helpers / devise_helper.rb)来获取闪存并使用那些如果设置然后默认为resource.errors 。 这只是基于设计库中的帮助程序。

 module DeviseHelper def devise_error_messages! flash_alerts = [] error_key = 'errors.messages.not_saved' if !flash.empty? flash_alerts.push(flash[:error]) if flash[:error] flash_alerts.push(flash[:alert]) if flash[:alert] flash_alerts.push(flash[:notice]) if flash[:notice] error_key = 'devise.failure.invalid' end return "" if resource.errors.empty? && flash_alerts.empty? errors = resource.errors.empty? ? flash_alerts : resource.errors.full_messages messages = errors.map { |msg| content_tag(:li, msg) }.join sentence = I18n.t(error_key, :count => errors.count, :resource => resource.class.model_name.human.downcase) html = <<-HTML 

#{sentence}

    #{messages}
HTML html.html_safe end end

我知道这已经过时了,但我最终在这里因为我在rails 5.1中遇到了同样的问题并且接受的答案没有奏效,所以这就是我所做的。 覆盖Devise :: SessionController后,将以下代码添加到其中:

 after_action :unauthenticated protected def unauthenticated flash[:alert] = t("devise.failure.#{request.env['warden'].message}") unless request.env['warden'].message.blank? end 

此外,在同一个控制器上,从您的Devise版本复制并粘贴create方法的代码,然后删除! 来自warden.authenticate! 。 因为你删除了! ,现在你必须检查资源是否为nil,如果是,则重定向。 在我的例子中,create方法最终如下:

 def create self.resource = warden.authenticate(auth_options) redirect_to root_path and return if resource.nil? set_flash_message!(:notice, :signed_in) sign_in(resource_name, resource) yield resource if block_given? respond_with resource, location: after_sign_in_path_for(resource) end 

最后,您只需在视图上打印Flash消息即可。 我正在使用materialize,所以我创建了一个partial并向其添加了以下代码(您应该根据自己的需要进行自定义):

 <% flash.each do |type, message| %> <% if type == "notice" %>  <% elsif type == "success" %>  <% elsif type == "alert" %>  <% end %> <% end %> 

Rails 5.1,Devise 4.4.3

在表单内部,可以显示错误:

 <% resource.errors.full_messages.each do |msg| %> <%= msg %> <% end %>