Passing parameter to controller action through rou

2019-04-21 13:08发布

问题:

Possible Duplicate:
Rails: How do I pass custom params to a controller method?

I am wondering if it possible to pass parameter to controller action through routes. I have a one generic action method which I want to call for various routes. No, I can't use wildcard in my route.

match '/about' => 'pages#show'
match '/terms' => 'pages#show'
match '/privacy' => 'pages#show'

I am looking for something like:

match '/about' => 'pages#show', :path => "about"
match '/terms' => 'pages#show', :path => "terms"
match '/privacy' => 'pages#show', :path => "privacy"

Thanks.

回答1:

Try

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

if you can't for some reason just follow the standard convention of

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