开发者

rails route to specific id

开发者 https://www.devze.com 2023-04-02 08:28 出处:网络
I have a pages controller with two records in the db; \'pages\' and \'contact\'. The id for each page record is the title.

I have a pages controller with two records in the db; 'pages' and 'contact'. The id for each page record is the title. How do I write a specific route for each page?

开发者_如何转开发

I currently have a catch-all route which works...

match '/:id' => 'pages#show'

but I want to create a single route for each page


I probably don't understand your question because I have no idea why you would want to do that ;)

Anyhow, say you have a page what the title/id "about". This is what your route could look like:

match '/about' => 'pages#show', :defaults => { :id => 'about' }

cf. http://guides.rubyonrails.org/routing.html#defining-defaults

Note: I wouldn't call the route you're using already a "catchall"; it's a pretty normal Rails route. This is what I would call a catchall:

match ':controller(/:action(/:id))'
0

精彩评论

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