2
我在routes.rb
中使用resources :users
。隨着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="https://stackoverflow.com/users/42" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Delete user</a>
我點擊鏈接,並帶我到秀頁?怎麼了?