我遇到了 Rails 5 的一个非常奇怪的问题。我有两个控制器,第一个 asusers_controller
和第二个 as api/v1/users_controller
。这两个控制器都有一个register
动作。我正在尝试向这两个控制器发布表单。此表单创建如下,
<%= form_tag('v2/register/user', {id: "add-user-form", class: "jiffle-form", role: "form"}) do%>
#form body
<%= submit_tag("Resigter", data: {i18n: "register"}, class: "btn btn-lg btn-block btn-blue", id: "add-user", type: "submit") %>
<% end %>
路线,
post "register" => "users#create", :as => "user_registeration_submit"
post "v2/register/user" => "api/v1/users#create"
当我使用/register
url 提交表单时,它会成功处理。但是,当我使用v2/register/user
url 提交表单时Can't verify CSRF token authenticity
出现错误。
参数
Processing by UsersController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"ADNTIp9alRB/ujRhkoqNuDkzdW6ANfcl/MbPjGLwVd6nwVuG5oi+uVhE9MeZo+1MeyKLbwZYNV31Vy/VH3M2bg==", "sfdc_token"=>"",
"email"=>"[FILTERED]", "first_name"=>"kjl", "last_name"=>"jk", "contact_no"=>"894892849", "company_name"=>"j", "title"=>"kj",
"internal_366vagan2"=>"", "consent"=>"true",
"commit"=>"Register"}
api/v1/users_controller
当我使用 ajax 在请求中使用X-CSRF-TOKEN标头提交表单时,它工作正常。
我在哪里进行更改以使我的 api/v1 控制器工作?