我已经成功地在这些链接中实现了一个失败的登录大纲后的自定义重定向...
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中添加一条闪信...
def redirect_url
login_path
flash[:notice] = "Invalid login or password"
end...but没有雪茄。理想情况下,我希望显示默认的devise错误消息。有办法做到这一点吗?
...also我在应用程序中的静态页面中显示我的登录和注册页面。因此,对于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 %>测试
发布于 2012-01-07 03:52:18
我最终将这些行添加到我的布局文件中,并且它起作用了。谢谢你的帮助马里奥。
<%= 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] %>发布于 2012-01-04 23:07:13
在您的自定义失败应用程序中,您应该能够在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
endhttps://stackoverflow.com/questions/8728226
复制相似问题