ruby on rails-I 301如何重定向这些路由更改



我有两条这样的路线:

  match ':category/:brand/:permalink' => 'products#show', :as => :public_product
  match 'stoves' => 'home#stoves', :as => :stoves

我把它们改成这个:

  match ':category/:brand/:permalink' => 'products#show', :as => :public_product
  match 'wood_stoves' => 'home#wood_stoves', :as => :stoves

我将标题为stoves的类别记录更改为wood_stoves

我可以添加一个路由重定向吗?该重定向允许通配符将domain.com/stovesdomain.com/stoves/morso/8140-contemporary分别更改为domain.com/wood_stovesdomain.com/wood_stoves/morso/8140-contemporary?或者我应该把它放在我的apachevirtualhost配置块中吗?

让你的route.rb像这样:

match ':category/:brand/:permalink' => 'products#show', :as => :public_product
match 'stoves' => 'home#stoves', :as => :old_stoves # anything else except stoves
match 'wood_stoves' => 'home#wood_stoves', :as => :stoves

在您的家庭控制器中:

def stove
  redirect_to stoves_path(# Use parameters here when a user hits a link like domain.com/stoves or domain.com/stoves/morso/8140-contemporary)
end
def wood_stoves
  # your code here..
end
match ':category/:brand/:permalink' => 'products#show', :as => :public_product
match 'stoves' => 'home#stoves', :as => :old_stoves # 
match 'wood_stoves' => 'home#stoves', :as => :stoves

我想这已经足够了。

如果你特别想把动作的名称改为wood_stoves,那么我认为你需要做Surya的解决方案

相关内容

  • 没有找到相关文章

最新更新