加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 使用flash消息登录失败后设计重定向

发布时间:2020-12-17 02:34:54 所属栏目:百科 来源:网络整理
导读:在这些链接中登录大纲失败后,我已成功实施自定义重定向… 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 但是,我没有在静态页面中获取相应
在这些链接中登录大纲失败后,我已成功实施自定义重定向…

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

但是,我没有在静态页面中获取相应的Flash消息.我尝试在custom_failure.rb中添加一条flash消息,就像这样……

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

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

…我也在我的应用程序的静态页面中显示我的登录和注册页面.所以对于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 %>

测试

解决方法

我最终将这些行添加到我的布局文件中,并且它可以工作.谢谢马里奥的帮助.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读