Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable Devises message - "You are already signed in." - when redirecting back the users index?

I have a button on my web page that redirects my from the user index with params back to the user index. My problem is that when I navigate back to the users_path through a button I get a message form devise saying "You are already signed in." This happens even though I was not trying to sign in and was only navigating back to the same page but removing the params.

The button in question looks like,

<%= button_to "All Users", users_path, class: "button expand" %> 

I searched all my files for instances of "You are already signed in." and the only refrence is in the devise.en.yml where it says already_authenticated: "You are already signed in."

like image 412
Allison Avatar asked Jan 21 '15 18:01

Allison


3 Answers

You can also edit the message in config/locales/devise.en.yml:

failure:
  already_authenticated: ''

Then wherever your flash messages are displayed in your view:

- if flash[:alert].present?
  ...
like image 123
meatrobot Avatar answered Nov 02 '22 05:11

meatrobot


The DeviseController is generating this message from method require_no_authentication. This method is used as a before_filter on pages like the one for signing in or other similar actions that are useless for signed in users. It redirect to the after_sign_in_path for the resource and sets that flash message. You'll have to either overwrite the require_no_authentication method or generate a new controller that does not use the before_filter.

like image 21
ptd Avatar answered Nov 02 '22 04:11

ptd


This was happening because I was using a button_to rather than a link_to. A button_to attaches a POST request as opposed to a link_to which attaches a GET request. With the attached post request rails was looking to a different action in the controller than the one intended.

If creating a refresh method on an index or show page always use a link_to helper or a helper that attaches a GET request.

like image 40
Allison Avatar answered Nov 02 '22 06:11

Allison