11

可能重复:
Rails:如何将自定义参数传递给控制器​​方法?

我想知道是否可以通过路由将参数传递给控制器​​动作。我有一个通用的操作方法,我想为各种路线调用它。不,我不能在我的路线中使用通配符。

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

我正在寻找类似的东西:

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

谢谢。

4

1 回答 1

18

尝试

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

如果由于某种原因你不能遵循标准约定

match '/:id' => 'pages#show'
于 2012-08-31T17:05:56.533 回答