我正在将我的rails应用程序移植到3.1.0(从2.3.8开始),并且正在进行重构。现在我有单独的模型/视图/控制器,以下两页。给定URL的内容覆盖rails路径/路径?
http://www.youhuntandfish.com/fishing/fishingstories/148-late-fall-brook-trout http://www.youhuntandfish.com/hunting/huntingstories/104-early-nine-pointer
'huntingstories' 和 'fishingstories' 实际上是一样的东西,所以我想分享的模型/视图/控制器。
这是问题所在。在视图中,我使用了像'huntingstories_path'和'fishingstories_path'这样的助手。我不想在整个视图中添加一堆条件来选择要使用的条件。我想要做的是写。
“stories_path”
而且有一些代码,这个映射给定的“/狩猎/”或“/钓鱼/”的URL的一部分打猎或是钓鱼。
有没有一种简单的方法在路径文件中做到这一点,还是我需要编写视图助手?如果我能有新的'/钓鱼/故事'和'狩猎/故事'的路线,并将旧路线重新引导到这些路线,情况会更好。
这里是现在的路线。
scope 'fishing' do
resources :fishingstories
resources :fishingspots
end
scope 'hunting' do
resources :huntingstories
resources :huntingspots
end
你的路由现在看起来如何?你使用嵌套路线吗? – nathanvda
我不这样做,但我正在使用范围方法。我添加了上面的故事和现场路线,因为我拥有它们。 – arons