Newbie question on has_may : through and link_to


#1

Ok. This is a stupid newbie question.

We have a database which has tables of topics, countries, countrynotes
and countrynotes_topics
(Any countrynote can relate to multiple topics and any topic can
relate to multiple country notes, each countrynote can relate to only
one country). What I want to do is when I show the index of topics,
each topic will have a link_to that will generate a index page of the
countrynotes related to that topic. Similarly, an index page of
countries should have a link_to which will generate an index of topics
related to that country and a link_to which will generate an index of
countrynotes related to that country. I have no problem doing this the
hard way through straight sql statements (that is how the program
works today [in a different language]). The question is what is the
best RESTful way to build the link_to in Rails?

class Topic < ActiveRecord::Base
has_many :countrynotes, :through => :countrynotes_topics
has_many :countrynotes_topics
end

class Countrynote < ActiveRecord::Base
belongs_to :country
has_many :countrynotes_topics
has_many :topics, :through => :countrynotes_topics
end

class CountrynoteTopic < ActiveRecord::Base
belongs_to :countrynote
belongs_to :topic
end