Passing parameter to controller action through routes [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-22 03:46:59

问题


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'


来源:https://stackoverflow.com/questions/12219436/passing-parameter-to-controller-action-through-routes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!