Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameter to controller action through routes [duplicate]

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.

like image 844
Firoz Ansari Avatar asked Aug 31 '12 16:08

Firoz Ansari


1 Answers

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'
like image 108
gregates Avatar answered Oct 08 '22 03:10

gregates