Reputation: 431
i have problem to build the 'link_to' to action "destroy".
I have two nested routes in 'Routes.rb':
namespace :admin do
namespace :security do
resources :users
end
end
'rake routes' prints:
DELETE /admin/security/users/:id(.:format) admin/security/users#destroy
the controller is:
class Admin::Security::UsersController < ApplicationController
def destroy
...
end
...
How to build the link_to with http veb 'delete'?
I unsuccessful tried:
<%= link_to 'destroy', user, method: :delete %>
<%= link_to 'destroy', {:controller => "admin/security/users", :action => "destroy", :id => user.id}, method: :delete %>
<%= link_to 'destroy', admin_security_users_path(user), method: :delete %>
<%= link_to 'destroy', admin_security_user_destroy_path(user), method: :delete %>
Upvotes: 0
Views: 988
Reputation: 660
You could try passing only the action and resources and leave the rest up to rails:
UPDATE
You should use namespaces names as a parameter to url_for
<%= link_to 'destroy', ([:destroy, :admin, :security, user]), method: :delete %>
Upvotes: 1
Reputation: 53018
Use this
<%= link_to 'destroy', admin_security_user_path(user), method: :delete %>
use admin_security_user_path
and not admin_security_users_path
NOTE: DELETE is performed on single object of model.
See the Official Rails Routing Documentation.
Upvotes: 0