Rails 3 破坏动作问题

发布于 2024-10-29 05:03:15 字数 337 浏览 1 评论 0原文

我正在尝试删除数据库中的一些行,但是当我调用销毁操作时,更新操作起作用。

这是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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暮年慕年 2024-11-05 05:03:16

路由中的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 the matchblock. Plus: seems like you mixed up the controller action and the http verb: use delete in the form action and destroy 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"

ζ澈沫 2024-11-05 05:03:15

:action 应该是 delete,以匹配控制器中操作的名称:

= form_for @post, :url => {:action => 'delete', :id => @post.id} do |f|

The :action should be delete, to match the name of the action in your controller:

= form_for @post, :url => {:action => 'delete', :id => @post.id} do |f|
哑剧 2024-11-05 05:03:15

如果您使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文