Devise inactive_message将不会显示

Mik*_*ley 1 ruby-on-rails devise

我试过实现active_for_authentication?和inactive_message在此处记录:

http://www.rubydoc.info/github/plataformatec/devise/Devise/Models/Authenticatable

我已经完成了那里列出的所有内容,但是当用户登录但用户没有活动状态时,非活动消息将不会显示给用户.

我在用户表上设置了一个名为"active"的布尔字段.我的检查将查看用户是否处于活动状态.

我做了一些调试,发现调用了inactive_message方法.我也查看了user.errors,它是空的.

问题是不会显示错误消息(inactive_message).

我做了一些研究,说它可能是因为监狱长而且你必须实现failure_app,但是我无法在failure_app上找到任何好的文档并为我的情况实现它.

我在签名时得到的确切错误是未经授权的401.

tre*_*iff 7

我有同样的问题,如果你知道该active_for_authentication?方法正在返回false它可能只是你没有在你的视图中显示闪存.例如,a User有一个enabled属性,当false active_for_authentication?返回false时.

此外,请确保这些方法不受保护/私有.

# /models/user.rb

def active_for_authentication?
  super && self.enabled == true
end

def inactive_message
  "User account has been disabled"
end
Run Code Online (Sandbox Code Playgroud)

确保在视图中有闪光灯设置,例如.

# /views/layouts/application.html.erb

<% flash.each do |name, msg| %>
  <%= content_tag(:div, msg, class: "alert alert-#{name}") %>
<% end %>
Run Code Online (Sandbox Code Playgroud)