Always read the errors carefully. There is actually useful information. Let's look at your example.
First, this entry:
ActiveRecord :: RecordNotFound in UsersController # show Couldn't find
tells us that we hit the UsersController#show . That is, in the action show .
Second, the value of params[:id] is edit_multiple
User with 'id' = edit_multiple
How did that happen? Let's try to figure it out.
You have an error in the call that forms the link_to helper, as noted by @Ilya Konyukhov. Instead of a POST request, the server receives a GET request.
Note that routing in the rails works on the principle of "first coincidence of the route" and then ceases to search. Therefore, on our GET request, the route will be chosen along the path /users/edit_multiple.id
get 'users/:id', to: 'users#show'
and accordingly instead of :id(.:format) will be edit_multiple.id . that is, in the params[:id] controller, edit_multiple will be equal and params[:format] will be equal to id
Now try to fix it. In order for the link_to form a POST request, you need to specify this in the helper:
<%= link_to "Delete", edit_multiple_users_path(:id), method: :post %>
Hurray we get into the edit_multiple action. And params[:id] still edit_multiple When searching for a suitable route, the router safely ignored
get 'users/:id', to: 'users#show'
but found the first suitable route for the method of our POST request:
post 'users/:id', to: 'users#edit_multiple', :as => :admin_edit_user
and according to this route, the pattern paths /users/:id(.:format). again we get params[:id] equal to edit_multiple , and params[:format] is equal to id , and params[:user_ids] completely absent.
and the route we need:
resources :users do collection do post :edit_multiple end end
ignored.
In order for us to form the correct query in the view, call the link_to call as follows
<%= link_to "Delete", edit_multiple_users_path(user_ids: @user_ids, commit: 'Delete'), method: :post %>
where @user_ids stores what you want to transfer to params [: user_ids]. Your way to call:
edit_multiple_users_path(:id)
does not define at all :user_ids , but determines :format . Remember the route in the / /users/edit_multiple(.:format) .: /users/edit_multiple(.:format) route.
Finally, the routing config:
root to: 'users#index' devise_for :users get '/users', to: 'users#users' get 'users/:id', to: 'users#show' resources :users do collection do post 'edit_multiple' end end
References:
about link_to here
Routing at RoR
Devise