【问题标题】:rails polymorphic nested comments - cant delete themrails 多态嵌套评论 - 不能删除它们
【发布时间】:2011-01-11 15:42:22
【问题描述】:

这里是我的 git https://gist.github.com/774510

问题是如果我在_comments.html.erb 中使用method:destroy,我会被发送到articles/1/comments,没有匹配的路由,而且评论不会​​被删除

如果我使用method:delete,我会被路由到正确的页面articles/1,但我的应用不会删除评论,而是创建一个新的:/

【问题讨论】:

    标签: ruby-on-rails-3 comments polymorphism nested-routes


    【解决方案1】:

    我相信您需要告诉 rails 评论嵌套在文章下,或者只需删除 cmets 控制器中的评论:

    1.)

    # routes.rb
    resources :articles do
      resources :comments
    end
    

    2.)

    # _comments.html.erb
    <%= link_to 'delete' comment, :method => :delete %>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-05
      • 2016-01-31
      • 2021-09-09
      • 1970-01-01
      • 2012-09-17
      • 2014-08-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多