Ruby on rails 为什么是id';从嵌套的路线切换到什么地方?

Ruby on rails 为什么是id';从嵌套的路线切换到什么地方?,ruby-on-rails,ruby-on-rails-3,routes,Ruby On Rails,Ruby On Rails 3,Routes,我的管理命名空间下有一个嵌套资源: admin/topic/comments\u controller.rb是admin/topics\u controller.rb下的资源 namespace :admin do resources :topics do resources :comments, :controller => "topic/comments" end end 给我这个删除路径: 删除 /管理员/主题/:主题\u id/评论/:id(:

我的管理命名空间下有一个嵌套资源:
admin/topic/comments\u controller.rb
admin/topics\u controller.rb
下的资源

  namespace :admin do
    resources :topics do
      resources :comments, :controller => "topic/comments"
    end
  end
给我这个删除路径:

删除
/管理员/主题/:主题\u id/评论/:id(:格式)
管理员/主题/评论#销毁

我正在创建一个链接来销毁评论,如下所示:

#comment=@topic.comment.first
:删除%>

生成以下路径:

/admin/topics/165/comments/11


所有这些似乎都是正确的,只是两个ID互换了。我做错了什么?

您可以改用路由名称:

<%= link_to "Destroy", admin_topic_comment_path(@topic, comment), :method => :delete %>
:删除%>
'destroy',:id=>comment.id,:method=>:delete%>

或者如果您使用RESTFUL路由:

comment.id),:方法=>:删除%>

使用名称空间控制器和路由时,必须使用名称空间模型,才能使
链接\u to
帮助器正常工作

e、 例如,在app/models/admin/comment.rb中

class Admin::Comment < Comment   
end
class Admin::Comment
这将生成
未定义的方法admin\u topic\u topic\u comment\u path
error谢谢,所以我想
[]
路由无法单独实现所有功能。毕竟需要命名路由助手方法。我发现这与