views:

83

answers:

3

Hi, I have just started learning ruby on rails. I have a doubt wrt routing.

Default Routing in Rails is :controller/:action/:id

It works really fine for the example lets say example.com/publisher/author/book_name

Could you tell me how do you work with something very big like this site

http://www.telegraph.co.uk/sport/football/leagues/premierleague/chelsea/

Could you let me understand about the various controllers, actions, ids for the above mentioned url and how to code controller, models so as to achieve this.

Could you suggest me some good tutorials when dealing with this big urls.

Looking forward for your help

Thanks in advance

Gautam

+1  A: 

The routing engine can handle URLs of arbitrary size. It all depends on what your spec is. For that it would be:

map.sport_league_team '/sport/:sport/leagues/:league/:team'

What controller you route that to is the important part. This is then called like:

<%= link_to("Chelsea", sport_league_team_path('football', 'premierleague', 'chelsea') %>

You can always examine what routes are defined with:

rake routes
tadman
+1  A: 

This is achieved using nested resources (read or google for "rails restful routes". In your case it could look something like this:

map.resources :sports do |sport|
  sport.resources :leagues do |league|
    league.resources :team
      # probably more nested routes for members or sponsors or whatever...
    end
  end
end

You can also view your defined routes with rake task:

$ rake routes

This RailsCasts episode also covers some basics on restful routing with nested resources.

Eimantas
A: 

The Rails Routing from the Outside In guide is a good place to start.

John Topley