Whats the meaning of :slug in route.rb (ruby on rails). How its mapped?
Whats the meaning of :slug in routes.rb (开发者_Python百科ruby on rails). How its mapped?
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" }
.
精彩评论