def new
@topic = Topic.find(params[:topic_id])
@comment = @topic.comments.build
end
Every request sent to the CommentsController will get the topic_id so
you can do nice things like listing all the comments for a particular
topic, etc.
You may want to consider introducing a new controller (Subtopics) that
specifically deals with "topics that have parent topics". You can
still use the same model for state/persistence but you will greatly
simplify your controller and view code by giving it a single focus.
With that in mind:
map.resources :topics do |topic|
topic.resources :subtopics
end
class TopicsController < ApplicationController
def index
@topics = Topic.find(:all, :order=>:name, ...)
...
end
...
end
class SubtopicsController < ApplicationController
def index
@topic.find(:all, :order=>:name)
@subtopics = @topic.children
...
end
end
This assumes a model that uses acts_as_tree or a similar data model
for connecting 'parent' topics with 'child' subtopics.