Rails 3 破坏动作问题
我正在尝试删除数据库中的一些行,但是当我调用销毁操作时,更新操作起作用。
这是delete.html.haml
=form_for @post, :url => {:action => 'destroy', :id => @post.id} do |f|
这是路线
resources :post
root :to => "post#index"
match '/delete/:id/', :to => "post#delete"
有什么问题吗?有人明白吗?
i am trying to delete some rows on my database but when i call destroy action, update action works.
this is delete.html.haml
=form_for @post, :url => {:action => 'destroy', :id => @post.id} do |f|
this is route
resources :post
root :to => "post#index"
match '/delete/:id/', :to => "post#delete"
What's the problem? Anybody does understand?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
路由中的
root
条目应放置在match
块之后。另外:似乎您混淆了控制器操作和http动词:在表单操作中使用delete
并在控制器操作调用中使用destroy
:=form_for @post , :url => {:动作=> '删除', :id => @post.id} do |f|
资源 :post
匹配 '/delete/:id/', :to => “发布#销毁”
根:到=> “帖子#index”
The
root
entry in your routes should be placed after thematch
block. Plus: seems like you mixed up the controller action and the http verb: usedelete
in the form action anddestroy
in the controller action call:=form_for @post, :url => {:action => 'delete', :id => @post.id} do |f|
resources :post
match '/delete/:id/', :to => "post#destroy"
root :to => "post#index"
:action
应该是delete
,以匹配控制器中操作的名称:The
:action
should bedelete
, to match the name of the action in your controller:如果您使用 Rails 3,那么您需要确保您有 <%= csrf_meta_tag %>在你的标题中。我把我的放在 <%= javascript_include_tag... %> 之后标签。还要确保包含rails.js。 (这将位于您的布局文件中)。
更多详细信息请参见:http://railsforum.com/viewtopic.php?id=38460向底部看去。
If you are using rails 3 then you need to make sure you have <%= csrf_meta_tag %> in your header. I put mine after my <%= javascript_include_tag... %> tags. Also make sure that you include the rails.js. (This will be on your layout files).
More details here: http://railsforum.com/viewtopic.php?id=38460 Look toward the bottom.