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.
我的网页上有一个按钮,用于将我的用户索引重定向到params回到用户索引。我的问题是,当我通过按钮导航回到users_path时,我会收到一条消息表单“你已经登录了”。即使我没有尝试登录并且只是导航回同一页面但删除了参数,这种情况也会发生。
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."
我搜索了所有文件中的“你已经登录了”的实例。并且唯一的参考是在devise.en.yml中,它表示已经经过验证:“你已经登录了。”
3 个解决方案
#1
7
You can also edit the message in config/locales/devise.en.yml:
您还可以在config / locales / devise.en.yml中编辑消息:
failure:
already_authenticated: ''
Then wherever your flash messages are displayed in your view:
然后,只要您的Flash消息显示在视图中:
- if flash[:alert].present?
...
#2
2
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
.
DeviseController从方法require_no_authentication生成此消息。此方法用作页面上的before_filter,例如用于登录的页面或对登录用户无用的其他类似操作。它重定向到资源的after_sign_in_path并设置该flash消息。您必须覆盖require_no_authentication方法或生成不使用before_filter的新控制器。
#3
1
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.
发生这种情况是因为我使用的是button_to而不是link_to。 button_to附加POST请求,而不是附加GET请求的link_to。通过附加的post请求rails在控制器中寻找的操作与预期的不同。
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.
如果在索引或显示页面上创建刷新方法,请始终使用link_to帮助程序或附加GET请求的帮助程序。
#1
7
You can also edit the message in config/locales/devise.en.yml:
您还可以在config / locales / devise.en.yml中编辑消息:
failure:
already_authenticated: ''
Then wherever your flash messages are displayed in your view:
然后,只要您的Flash消息显示在视图中:
- if flash[:alert].present?
...
#2
2
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
.
DeviseController从方法require_no_authentication生成此消息。此方法用作页面上的before_filter,例如用于登录的页面或对登录用户无用的其他类似操作。它重定向到资源的after_sign_in_path并设置该flash消息。您必须覆盖require_no_authentication方法或生成不使用before_filter的新控制器。
#3
1
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.
发生这种情况是因为我使用的是button_to而不是link_to。 button_to附加POST请求,而不是附加GET请求的link_to。通过附加的post请求rails在控制器中寻找的操作与预期的不同。
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.
如果在索引或显示页面上创建刷新方法,请始终使用link_to帮助程序或附加GET请求的帮助程序。