【发布时间】:2011-03-29 21:29:40
【问题描述】:
我在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="/users/42" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Delete user</a>
我点击该链接,它会将我带到显示页面?!怎么了?
【问题讨论】:
标签: ruby-on-rails-3 routes resources restful-url