错误的路线处理表格提交

时间:2015-08-06 03:03:37

标签: ruby-on-rails forms devise routing

我有一个设计编辑注册表单的扩展版本,当我提交它而不是由update方法处理时,它由create方法处理。我无法弄清楚原因。

当我在日志中提交表单时,我得到:

Started POST "/users" for ::1 at 2015-08-05 20:49:28 -0600
Processing by Users::RegistrationsController#create as HTML

在我看来,这就是我生成表单标签的方式:

form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put,class:"form-horizontal" }) do |f| ... end
来自佣金路线的相关产出:

cancel_user_registration GET    /users/cancel(.:format)                 users/registrations#cancel
       user_registration POST   /users(.:format)                        users/registrations#create
   new_user_registration GET    /users/sign_up(.:format)                users/registrations#new
  edit_user_registration GET    /users/edit(.:format)                   users/registrations#edit
                         PATCH  /users(.:format)                        users/registrations#update
                         PUT    /users(.:format)                        users/registrations#update
                         DELETE /users(.:format)                        users/registrations#destroy

和渲染的表单html:

<form class="form-horizontal" id="edit_user" action="/users" accept-charset="UTF-8" method="post">
<input name="utf8" value="✓" type="hidden">
<input name="_method" value="put" type="hidden">
<input name="authenticity_token" value="snip" type="hidden">
...
<input name="commit" value="Update" class="btn btn-success" type="submit">
</form>

我刚刚继续开始评论大量显然不相关的代码,结果发现以下字段导致了这个问题:

<input name="user[doctor_ids][]" value="" type="hidden">
<select multiple="multiple" name="user[doctor_ids][]" id="user_doctor_ids">
  <option value="2">House</option>
</select>
<input value="2" name="user[doctor_ids][]" id="user_doctor_ids_2" type="checkbox">
<input name="user[doctor_ids][2][token]" id="user_doctor_ids_2_token" type="text">

请注意重复的name="user[doctor_ids][]",但仍然不知道为什么这会妨碍路由,但至少我可以修复它。我只是想在每种情况下提交类似的内容时看看这些参数是什么样的。

0 个答案:

没有答案