JJD*_*JJD 2 resources routes restful-url ruby-on-rails-3
我使用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"}
Run Code Online (Sandbox Code Playgroud)
此外,我评论了传统的野外控制器路由.
#match ':controller(/:action(/:id(.:format)))'
Run Code Online (Sandbox Code Playgroud)
要在我的用户页面上添加删除链接,我添加以下内容.
<%= link_to "Delete user", user, :method => :delete, :confirm => "Are you sure?" %>
Run Code Online (Sandbox Code Playgroud)
这生成了以下html代码.
<a href="/users/42" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Delete user</a>
Run Code Online (Sandbox Code Playgroud)
我点击链接,它将我带到显示页面?!怎么了?
您需要包含默认的Javascript文件才能正常工作:
<%= javascript_include_tag :defaults %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
429 次 |
| 最近记录: |