How to disable the message Devises - "You are already logged in." - when redirecting a user index?

I have a button on my webpage that redirects mine from a user index with parameters back to the user index. My problem is that when I go back to the users_path via the button, I get a message form form that says: "You are already logged in." This happens even though I did not try to log in and went only to one page, but deleted the settings.

This button looks like this:

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

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

+5
source share
3 answers

This happened because I used button_to, not the link_to. The button_to button attaches the POST request, not the link_to, which attaches the GET request. With the attached rails of the departure request, I was looking for a different action in the controller than planned.

When creating an update method on an index or impression page, always use the link_to helper or the helper that attaches the GET request.

+1
source

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

 failure: already_authenticated: '' 

Then wherever your flash messages appear in your view:

 - if flash[:alert].present? ... 
+7
source

DeviseController generates this message from the require_no_authentication method. This method is used as before_filter on pages, for example, for login or other similar actions that are useless for subscribed users. It redirects to after_sign_in_path for the resource and sets this flash message. You will either have to overwrite the require_no_authentication method, or generate a new controller that does not use before_filter .

+2
source

Source: https://habr.com/ru/post/1211644/


All Articles