Mike Riley
Mike Riley

Reputation: 292

Devise inactive_message won't display

I have tried implementing the active_for_authentication? and inactive_message that is documented here:

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

I have done everything listed there, but the inactive message will not display to the user when they sign in but the user does not have an active state.

I have set up a boolean field on the user table called "active." My check will see if the user is active or not.

I did some debugging and found that the inactive_message method is called. I also looked at the user.errors and it is empty.

The issue is that the error message (inactive_message) doesn't get displayed.

I did some research that says it may be because of warden and that you have to implement failure_app, but I was not able to find any good documentation on failure_app and implementing it for my situation.

The exact error I am getting when signing is a 401 unauthorized.

Upvotes: 1

Views: 2302

Answers (1)

treiff
treiff

Reputation: 1306

I had the same issue, if you know the active_for_authentication? method is returning false it could simply be your not showing the flash in your view. For example, a User has a enabled attribute, when false active_for_authentication? returns false.

Also, be sure these methods aren't protected/private.

# /models/user.rb

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

def inactive_message
  "User account has been disabled"
end

Make sure you have flash setup in the view, something like.

# /views/layouts/application.html.erb

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

Upvotes: 7

Related Questions