我正在使用resources :users
. routes.rb
这提供了以下路径作为rake routes
揭幕。
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"}
此外,我注释掉了遗留的野控制器路由。
#match ':controller(/:action(/:id(.:format)))'
要在我的用户页面上添加删除链接,我添加以下内容。
<%= link_to "Delete user", user, :method => :delete, :confirm => "Are you sure?" %>
这生成了以下 html 代码。
<a href="/users/42" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Delete user</a>
我点击链接,它带我到展示页面?!怎么了?