如何从静态站点向rails应用程序发布请求



我首先在一个域app.example.com中创建了rails应用程序,并在另一域www.example.com中创建了静态站点。然后在rails应用程序中添加devisegem,并在静态站点中创建一个登录表单。这是登录表单的代码:

<form action="app.example.com/users/sign_in" method="post">
<input name="utf8" type="hidden" value="✓">
Email:<input type="text" name="email" value="admin@gmail.com">
Password:<input type="password" name="password" value="password">
<input name="authenticity_token", value="", type="hidden">
<button>Submit</button>
</form>

从静态站点登录后是否可以重定向到rails应用程序,因为它需要authenticity_token,并且在静态站点中很难生成authenticity_token,而且可能存在csrf的问题。

您可以通过子类化Devise::SessionsController来禁用此操作的CSRF保护。

# app/controllers/my_sessions_controller.rb
class MySessionsController < Devise::SessionsController
skip_before_action :verify_authenticity_token, only: :create
end

确保在config/routes.rb:中更改devise_for :users调用

devise_for :users, controllers: { sessions: 'my_sessions' }

最新更新