开发者

Rails 3 route question: use top level url based on model name not id

开发者 https://www.devze.com 2023-03-18 00:54 出处:网络
I am writing a rails 3 application and want to chan开发者_高级运维ge an existing route that goes like:

I am writing a rails 3 application and want to chan开发者_高级运维ge an existing route that goes like:

domain.com/tapes/2

to that:

domain.com/tapename

i.e., instead of fetching the default route based on resource 'tapes' id, I want the app to match any string 'tapename' to the show page of the corresponding record.

Could you please point me to the right direction? Thank you very much for your time.


Add a new match statement as the last route in your routes.rb file (if you put it earlier, it'll be matched before other resources; and of course, make sure your shows resource is listed before the match statement):

resources :shows
match "/:id" => "tapes#show"
0

精彩评论

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