Named route from resources takes me to show page instead of delete page
I am using resources :users
in routes.rb
. This provides the following paths as rake routes
unveils.
users GET /users(.:format) {:action=>"index", :controller=>"users"}
POST /users(.:format) {:action=>"create", :controller=>"users"}
new_user GET /users/new(.:format) {:action=>"new", :controller=>"users"}
edit_user GET /users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
user GET /users/:id(.:format) {:action=>"show", :controller=>"users"}
PUT /users/:id(.:format) {:action=>"update", :controller=>"users"}
DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"}
Further, I comment out the legacy wild con开发者_运维技巧troller route.
#match ':controller(/:action(/:id(.:format)))'
To add a delete link on my users page I add the following.
<%= link_to "Delete user", user, :method => :delete, :confirm => "Are you sure?" %>
This generated the following html code.
<a href="/users/42" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Delete user</a>
I click the link and it takes me to the show page?! What's wrong?
You need to include the default Javascript files for that to work properly:
<%= javascript_include_tag :defaults %>
精彩评论