views:

34

answers:

1

Whats the meaning of :slug in routes.rb (ruby on rails). How its mapped?

+1  A: 

As with any other name, :param syntax means that this part of the url corresponds to a parameter named param.

So, taking an example of how SO urls are defined, we can observe the following route:

map.connect "/questions/:id/:slug", :controller => "questions", :action => "show"

And when you come to an url of the form http://stackoverflow.com/questions/3082982/whats-the-meaning-of-slug-in-route-rb-ruby-on-rails-how-its-mapped, it will be handled by QuestionsController#show with the params hash { :id => "3082982", :slug => "whats-the-meaning-of-slug-in-route-rb-ruby-on-rails-how-its-mapped" }.

neutrino
So for example, if I give like this map.root :controller => "pages", :action => 'show', :slug => "**homepage**"what will happen?
Aadi
this will only make all requests to your root route to `PagesController#show` with params `{ :slug => "**homepage**" }`. You're probably misunderstanding the concept of how slugs work in rails. See http://stackoverflow.com/questions/1871267/rails-restful-routing-with-and-slugs , and generally, search rules)
neutrino