Splitting Routes File Into Multiple Files

前端 未结 4 1556

I\'m working w/ a Rails 3 application and I want to split up the routes into separate files depending on the subdomain. Right now I have this in my routes.rb file:



        
4条回答
  •  無奈伤痛
    2020-12-18 21:48

    Sunkencity's answer seems to be identical to the following link, but for completeness' sake: https://rails-bestpractices.com/posts/2011/05/04/split-route-namespaces-into-different-files/

    Note that routes defined later will override routes defined earlier. However, if you use something like

        config.paths.config.routes.concat(
            Dir[Rails.root.join('config/routes/*.rb')])
    

    you don't know in what order the files will be read. So use

        config.paths.config.routes.concat(
            Dir[Rails.root.join('config/routes/*.rb')].sort)
    

    instead, so you at least know they will be in alphabetical order.

提交回复
热议问题