Friday, August 1, 2008

The two purposes of Rails Routing


Rails Routing is defined in ./config/route.rb. Routings are actually a list of rules.

Routing has two purposes.


  • Recognize URL: What to do when an URL like
    http://localhost:3000/myrecipes/apples
    is coming.

  • Generate URL: What to create when Rails command like

    link_to :controller=>'recipes',
    :action=>'show',
    :ingredient=>'apple'

    is defined.




map.connect "myrecipes/:ingredient",
:controller=>"recipes",
:action=>"show"



The static text is myrecipes.

The wildcard receptor is :ingredient which you can get by
params[:ingredient]

No comments: