简体   繁体   English

active_admin中没有路由与[PUT]错误匹配

[英]No route matches [PUT] error in active_admin

in active_admin partials created a form input: 在active_admin局部中创建了一个表单输入:

<%= semantic_nested_form_for @item, :url => admin_items_path(@item) do |f| %>
  <fieldset class="inputs">
    <ol>
      <%= f.input :category %></br>
      <%= f.input :title  %>
      <%= f.input :photo1 %>
      <%= f.input :photo2 %>
    </ol>
  </fieldset>
  <%= f.fields_for :ItemColors do |i| %>
    <fieldset class="inputs">
      <ol>
        <%= i.input :DetailColor %>
        <%= i.input :size,  :input_html => { :size => "10" } %>
        <%= i.link_to_remove "remove" %>
      </ol>
    </fieldset>
  <% end %>
  <%= f.link_to_add "add", :ItemColors %>
  <%= f.actions %>
<% end %>

to create a new Item okay creates and throws On the New Item, but if I do update an existing item is routed to an error occurs while such a path exists: 创建一个新项目,可以创建并抛出新项目,但是如果我确实更新了现有项目,则该路径存在时会发生错误:

No route matches [PUT] "/admin/items.150" #150 is item_id

rake routes: 耙路:

batch_action_admin_items POST   /admin/items/batch_action(.:format)   admin/items#batch_action
admin_items GET                 /admin/items(.:format)                admin/items#index
POST                            /admin/items(.:format)                admin/items#create
new_admin_item GET              /admin/items/new(.:format)            admin/items#new
edit_admin_item GET             /admin/items/:id/edit(.:format)       admin/items#edit
admin_item GET                  /admin/items/:id(.:format)            admin/items#show
PUT                             /admin/items/:id(.:format)            admin/items#update
DELETE                          /admin/items/:id(.:format)            admin/items#destroy

help to solve this problem 帮助解决这个问题

UPD UPD

I found the error, but not yet understood how to fix it 我找到了错误,但还不知道如何解决

the upgrade is a request: 升级是一个要求:

PUT "/admin/items.150"

but should: 但应:

PUT "/admin/items/150"

I can not understand where the address appears "." 我不明白该地址出现在哪里。

Your form is submitting data with the :method => POST while your route is expecting PUT , POST only matches 您的表单正在使用:method => POST提交数据,而您的路线希望使用PUT ,则POST仅匹配

POST /admin/items(.:format) admin/items#create

So it thinks that your ID is a .:format parameter. 因此,它认为您的ID是.:format参数。 And thus failing. 因此失败了。 You need to change your form :method to PUT instead of POST . 您需要将form:method更改为PUT而不是POST

You should be able to just do this: 您应该能够做到这一点:

<%= semantic_nested_form_for [:admin, @item] do |f| %>

As @cdesrosiers points out, the No route matches [GET] "/items/152" error you subsequently get is probably because you are redirecting to @item in your controller create and update actions, when you actually need to do this: 作为@cdesrosiers指出, No route matches [GET] "/items/152"错误,您随后得到的是可能是因为你重定向到@item在你的控制器createupdate的动作,当你真正需要做的是:

redirect_to admin_item_path(@item)

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

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