我們的網站應該允許顯示與給定的網址有關的不同內容..就像在wordpress中的多站點,我們有一個安裝和根據url提供內容。Rails路由請求routes.rb動態路由
由於需要以正確的語言顯示路線,我想使用「動態路線」方式來提供正確的內容。我的問題是,現在我沒有找到一個方法如何在routes.rb中服務正確的路由,如果它們是動態的。
我如何「訪問」或「關」 請求對象到的routes.rb文件
F.E.內的任何方法這樣
的routes.rb
Frontend::Application.routes.draw do
DynamicRouter.load request
end
應用程序/模型/ dynamic_router.rb
class DynamicRouter
def self.load request
current_site = Site.find_by_host(request.host)
Frontend::Application.routes.draw do
current_site.routes do |route|
get "#{route.match}", to: "#{route.to}"
end
end
end
end
這並不工作,因爲請求在routes.rb中
所以,基本上,你要支持所有的路線再次
抓住它的代碼? –
我想有每個網站的動態路線.. f.e.如果對於我們的某個網站,我想要調用/ category /:id,對於另一個網站,應該是/ category /:slug它應該能夠做到這一點 如果我只是將請求對象從routes.rb傳遞到模型方法,我已經知道我可以怎樣做其餘 – Mik
/category /:id和/ category /:slug是相同的路線。唯一的區別是,第一個動態部分將被存儲在params [:id]中,第二個是params [:slug] –