开发者

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

开发者 https://www.devze.com 2023-01-04 08:21 出处:网络
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.

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" }.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号