我正在尝试删除数据库中的一些行,但是当我调用销毁操作时,更新操作有效。
这是 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"
有什么问题?有人明白吗?
我正在尝试删除数据库中的一些行,但是当我调用销毁操作时,更新操作有效。
这是 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"
有什么问题?有人明白吗?
:action
应该是delete
,以匹配控制器中的操作名称:
= form_for @post, :url => {:action => 'delete', :id => @post.id} do |f|
路线中的条目应root
放在块之后match
。加:好像你混淆了控制器动作和http动词:delete
在表单动作和destroy
控制器动作调用中使用:
=form_for @post, :url => {:action => 'delete', :id => @post.id} do |f|
resources :post
match '/delete/:id/', :to => "post#destroy"
root :to => "post#index"
如果您使用的是 rails 3,那么您需要确保您的标题中有 <%= csrf_meta_tag %>。我把我的放在我的 <%= javascript_include_tag... %> 标签之后。还要确保包含 rails.js。(这将在您的布局文件中)。
更多细节在这里:http ://railsforum.com/viewtopic.php?id= 38460 往底部看。