Rails 3 route question: use top level url based on model name not id
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"
精彩评论