简体   繁体   中英

No route matches [PUT] error in active_admin

in active_admin partials created a form input:

<%= 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

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

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

So it thinks that your ID is a .:format parameter. And thus failing. You need to change your form :method to PUT instead of 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:

redirect_to admin_item_path(@item)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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