我是新的红宝石,有一个半复杂的路线,我想要建立创建动态网站地图,列出乔布斯在我们的网站
我的控制器名为SiteMap,SiteMap的路由位置是查询的'q‘
我们已经有工作了
URL签名的一部分由常量值组成,这些值有助于确定要使用的三种路由类型中的哪一种。
-jobs后缀将设置:industry param:industry => hospitality
jobs-in-前缀将设置:location:location => sydney
:industry => hospitality:location => sydney
如果有丰富的变量表示动态数据和类型(即type = Industry ),我要么想根据路径进行3个不同的操作,要么就选择一个操作。
发布于 2015-01-07 00:27:44
我认为唯一能做到这一点的方法就是使用一条通航路线:
get '/j/*path', to: 'jobs#route'(控制器操作需要更好的名称。)
该操作使用您的逻辑读取路径,并使用redirect_to使用适当的参数将路径路由到正确的路径。
发布于 2015-01-07 01:56:34
我让所有三条路线都能工作,再加上第四条抓捕所有错误URL的路径
get '/q/(:industry)-jobs' => 'sitemap#industry', :as => :sitemap_by_industry
get '/q/jobs-in-(:location)' => 'sitemap#location', :as => :sitemap_by_location
get '/q/(:industry)-jobs/in-(:location)' => 'sitemap#industry_location', :as => :sitemap_by_industry_location
# This catch is used if someone starts playing around with the URL's and we can't map to the three listed routes
get '/q(/:bad1(/:bad2))' => 'sitemap#sitemap', :as => :sitemap:industry => hospitality
:location => sydney
:industry => hospitality:location => sydney
https://stackoverflow.com/questions/27809351
复制相似问题