Ruby on rails 在登录失败后使用flash消息设计重定向

Ruby on rails 在登录失败后使用flash消息设计重定向,ruby-on-rails,devise,Ruby On Rails,Devise,我已经成功地实现了自定义重定向后,失败的登录大纲在这些链接 但是,我没有在我的静态页面中获得适当的flash消息。我尝试在custom_failure.rb中添加一条flash消息,如下所示 def redirect_url login_path flash[:notice] = "Invalid login or password" end …但是没有雪茄。理想情况下,我希望显示默认的Desive错误消息。有办法吗 …我还在应用程序的静态页面中显示我的登录和注册页面。所以对于ap

我已经成功地实现了自定义重定向后,失败的登录大纲在这些链接

但是,我没有在我的静态页面中获得适当的flash消息。我尝试在custom_failure.rb中添加一条flash消息,如下所示

def redirect_url
  login_path
  flash[:notice] = "Invalid login or password"
end
…但是没有雪茄。理想情况下,我希望显示默认的Desive错误消息。有办法吗

…我还在应用程序的静态页面中显示我的登录和注册页面。所以对于app/views/static_pages/login.html.erb中的实例,我有

<%= form_for("user", :url => user_session_path) do |f| %>
<table>
<tr>
<td><%= f.label :email %></td>
<td><%= f.text_field :email %></td>
</tr>
<td><%= f.label :password %></td>
<td><%= f.password_field :password %></td>
</table>
<%= f.check_box :remember_me %>
<%= f.label :remember_me %><p/>
<%= f.submit 'Sign in' %><p/>
<%= link_to "Forgot your password?", new_password_path('user') %>
<% end %>
user_session_path)do | f |%>


测试

在自定义故障应用程序中,您应该能够在
响应
方法中设置闪存消息,如下所示:

class CustomFailure < Devise::FailureApp
  def redirect_url
    login_path
  end

  # You need to override respond to eliminate recall
  def respond
    if http_auth?
      http_auth
    else
      flash[:notice] = I18n.t(:unauthenticated, :scope => [ :devise, :failure ])
      redirect
    end
  end
end
class CustomFailure[:designe,:failure])
重新使用
结束
结束
结束

我最终将这些行添加到我的布局文件中,并且工作正常。谢谢你的帮助,马里奥

<%= content_tag(:div, flash[:error], :id => "flash_error") if flash[:error] %>
<%= content_tag(:div, flash[:notice], :id => "flash_notice") if flash[:notice] %>
<%= content_tag(:div, flash[:alert], :id => "flash_alert") if flash[:alert] %>
如果闪烁[:错误]> “闪光通知”)如果闪光[:通知]]> 如果闪烁[:警报]]>
感谢Mario的回复。我试过你的建议,但确实奏效了。你能想出什么原因吗?塔克斯!不是这样,你的应用程序肯定使用你创建的自定义失败类吗?你能试着在respond方法中增加一点,以确保代码正在运行吗?嘿,Mario,在看了更多之后,我认为问题已经出现了。我不需要在视图中显示flash消息吗?下面是我的视图,它是app/views/static\u pages/login.html.erb有趣的。我发现,当我将“[:designe,:failure])%>”放入视图时,我会收到一条消息“您需要登录或注册才能继续”,因此这肯定是designe发出的,但这是我收到的唯一消息。如果我输入了错误的密码,我不会收到其他消息。哦,是的,这是设计/失败消息,您可以将其更改为其他消息,或者在此处检查现有的设计翻译。