开发者

Named route from resources takes me to show page instead of delete page

开发者 https://www.devze.com 2023-02-21 03:49 出处:网络
I am using resources :users in routes.rb. This provides the following paths as rake routes unveils. usersGET/users(.:format){:action=>\"index\", :controller=>\"users\"}

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

精彩评论

暂无评论...
验证码 换一张
取 消