设计重定向后,登录失败的flash消息



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

设置登录失败后的重定向https://github.com/plataformatec/devise/wiki/How-To: -Redirect-to-a-specific-page-when-the-user-can-not-be-authenticated

然而,我没有得到适当的flash消息在我的静态页面。我尝试在custom_failure中添加一个flash消息。

def redirect_url
  login_path
  flash[:notice] = "Invalid login or password"
end

…但是没有雪茄。理想情况下,我希望显示默认的设计错误消息。有什么办法吗?

…我也显示我的登录和注册页面在静态页面在我的应用程序。所以例如在app/views/static_pages/login.html。动词I have…

<%= 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 %>
测试

我最终将这些行添加到我的布局文件中,并且它有效。谢谢你的帮助,马里奥。

<%= 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] %>

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

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

相关内容

最新更新