Rails 3.2, No Route Matches { :controller=>'xxx' :action=>'xxx\" }

混江龙づ霸主 提交于 2019-12-08 07:25:27

You're conflating singular and plural resources. The edit_multiple_path route is currently configured as a singular resource, meaning that it expects a single Person to be passed as an argument. However, by definition, you're trying to update multiple people at a single time – it doesn't make sense to use a singular route, in this case.

Instead, try a collection route:

# config/routes.rb
resources :people
    collection do
        post 'update_multiple/:people_ids', :action => 'update_multiple'
    end
end

This will make the following route available:

       update_multiple_invites POST   /invites/update_multiple/:people_ids(.:format) invites#update_multiple

EDIT:

In the index view, you'll need to output your forms in order for them to be displayed:

# app/views/people/index.html.erb
<%= form_tag edit_multiple_people_path do %>

# app/views/people/_edit_multiple.html.erb
<%= form_for :person, :url => update_multiple_people_path, :html => { :method => :put } do |f| %>

Note that <% %> interprets everything enclosed within, but does not output it. You need to use <%= %> in order to actually output the form's contents.

Also, don't forget that your partial needs the extension .erb in order for it to interpret Ruby code. Perhaps you've named it accordingly, but your post depicts the name edit_multiple.html without the .erb.

On submit take a look at the code inspector and verify if you are getting routed to an GET request.

If you are getting a 404 that results in a GET request instead of a PUT request, it's because the :method => :put option relied on JavaScript. You'll need to make sure jquery-rails is properly integrated in your app.

You are trying to get this route:

No route matches {:controller=>"people", :action=>"edit_multiple"}

but in route.rb you are including :id attribute witch is requred

people/:id/edit_multiple

So in form you need to include person id

try out following code to get this route {:controller=>"people", :action=>"edit_multiple"}

resources :people do               
 collection do         
  get :edit_multiple       
  put :update_multiple       
 end        
end      
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!