Forum: Ruby on Rails Newbie question on has_may : through and link_to

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
1aec7caf6db09ae5939054f7e6b51ad1?d=identicon&s=25 wol (Guest)
on 2007-02-18 01:41
(Received via mailing list)
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

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

class CountrynoteTopic < ActiveRecord::Base
belongs_to :countrynote
belongs_to :topic
This topic is locked and can not be replied to.