class Topic < ActiveRecord::Base
  has_many   :posts
end
class Post < ActiveRecord::Base
  belongs_to :topic
  has_many   :comments
end
class Comment < ActiveRecord::Base
  has_ancestry
  belongs_to :开发者_开发问答post
end
MyApp::Application.routes.draw do
  resources :posts do
    resources :comments
  end
  resources :topics
  root :to => "posts#index"
end
Is my routes.rb in the correct order?
When it comes to routing, "correct" is pretty subjective. What you have here is totally valid, assuming it's producing the routes that you want. With this, you will have comments nested within posts, and topics at the root. Another option you have is to also nest posts within topics for URLs that looks something like:
/topics/1/posts
/topics/1/posts/1
With the following change:
MyApp::Application.routes.draw do
  resources :posts do
    resources :comments
  end
  resources :topics do
    resources :posts do
  end
  root :to => "posts#index"
end
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论