首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >登录失败后设备重定向,并显示闪光消息

登录失败后设备重定向,并显示闪光消息
EN

Stack Overflow用户
提问于 2012-01-04 22:09:05
回答 2查看 6K关注 0票数 4

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

Devise redirect after login fail https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-when-the-user-can-not-be-authenticated

然而,我没有得到适当的闪光信息在我的静态页面。我试着像这样在custom_failure.rb中添加一条闪信...

代码语言:javascript
复制
def redirect_url
  login_path
  flash[:notice] = "Invalid login or password"
end

...but没有雪茄。理想情况下,我希望显示默认的devise错误消息。有办法做到这一点吗?

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

代码语言:javascript
复制
<%= 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 %>

测试

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-01-07 03:52:18

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

代码语言:javascript
复制
<%= 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] %>
票数 3
EN

Stack Overflow用户

发布于 2012-01-04 23:07:13

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

代码语言:javascript
复制
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
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8728226

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档