ruby - Rails access request in routes.rb for dynamic routes -


Our websites should allow different materials related to the URL given. Like a multisite in WordPress, where We have an installation and serve the content according to the URL.

Because it is necessary to have a path in the right language, I want to use the "dynamic path" to serve the right material. My problem is how can I serve the proper routes in the streets, if they are moving

F.E. How can I "reach" or "pass" the request object in any method within the routes. E.g.

passRB

  frontend :: application.routes.draw Please end the dynamic router request  

app / model /dynamic_router.rb

  Category DynamicRouter def self.load Request current_site = Site.find_by_host (request.host) Frontend :: application.routes.draw Turn current_site.routes current. Route | To get "# {Route.match}": "# {route.to}" Get End End End  

This does not work because the request is not mandatory in routes. RB

A possible redress is to create the default rule on rout.rb and add a rack middleware which Can change domain according to path

  # routes.rb get '/ category /: id' ,: to = & gt; In the middle class, you can change a path like '/ category /: id' from 'categoria /: id' if matches 'matches' in 'Category # show'  

. The application router hits the layer.

More on Rack Middleware:


Comments