Search code examples
ruby-on-railsruby-on-rails-3ruby-on-rails-3.2ruby-on-rails-3.1

How to setup my article relationship


I want to make a article model.

A article belongs_to country
A article belongs_to region
A article belongs_to accomodation

So i want create listing like...give me articles from region X, give me articles from accomodation X.

The url structure looks like this:

/en/italy/articles
/en/italy/tuscany/articles
/en/italy/tuscany/accomodation_x/articles
ect

It is possibly in the a future that article has nothing todo with a accomodation, country or accomodation. By example company news ect

The url structure looks like this:

/en/articles

And on my homepage i want a show all new articles, with different paths. Point root_path of articles but also to the country_region_articles paths.

What is the best approach to setup the db relationsships?

Thanks..

remco


Solution

  • You might want to check these two casts too. On tagging and virtual attributes:

    http://railscasts.com/episodes/167-more-on-virtual-attributes http://railscasts.com/episodes/382-tagging