Whats the meaning of :slug in routes.rb (ruby on rails). How its mapped?
Asked
Active
Viewed 1,535 times
1 Answers
4
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" }
.

alex.zherdev
- 23,914
- 8
- 62
- 56
-
So for example, if I give like this map.root :controller => "pages", :action => 'show', :slug => "**homepage**" what will happen? – Aadi Jun 21 '10 at 09:04
-
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) – alex.zherdev Jun 21 '10 at 11:07