通过路由将参数传递给控制器动作 [英] Passing parameter to controller action through routes
本文介绍了通过路由将参数传递给控制器动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有可能通过路由将参数传递给控制器动作。我有一个通用的动作方法,我想调用各种路线。不,我不能在路径中使用通配符。
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"
谢谢。
推荐答案
尝试
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'
这篇关于通过路由将参数传递给控制器动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文