我有两条这样的路线:
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/stoves
或domain.com/stoves/morso/8140-contemporary
分别更改为domain.com/wood_stoves
或domain.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的解决方案