简体   繁体   English

Ruby on Rails Devise - 身份验证后重定向到 POST 请求

[英]Ruby on Rails Devise - Redirecting to POST request after authentication

Devise has redirect functionality allowing user to return to the page he was on before logging in. Devise 具有重定向功能,允许用户返回到登录前所在的页面。

The problem is it only works with GETs.问题是它只适用于 GET。 If the user was stopped for authentication during a POST (eg filling out a form) he will be redirected accordingly but with a GET.如果用户在 POST 期间停止进行身份验证(例如填写表格),他将相应地重定向,但使用 GET。

Is there any way to change this so the POST is completed correctly?有什么方法可以更改此设置以便正确完成 POST?

Many thanks.非常感谢。

You can redirect to a POST action, with the help of the repost gem.repost gem 的帮助下,您可以重定向到 POST 操作。

See the full solution here: Devise redirect after sign_in and perfom POST action在这里查看完整的解决方案: Devise redirect after sign_in and perfom POST action

Make sure u have _links.erb file in C:\\Ruby192\\lib\\ruby\\gems\\1.9.1\\gems\\devise-1.1.5\\app\\views\\devise\\shared(path may vary) with the following content . 确保您在C:\\ Ruby192 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ devise-1.1.5 \\ app \\ views \\ devise \\ shared中具有_links.erb文件(路径可能有所不同),其内容如下。

<%- if controller_name != 'sessions' %>
  <%= link_to "Sign in", new_session_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
  <%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
  <%= link_to "Didn't receive confirmation instructions?",   new_confirmation_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) &&  controller_name != 'unlocks' %>
  <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>    <br />
<% end -%>

Hope u get the solution. 希望你得到解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM