Skip to content

Instantly share code, notes, and snippets.

@mreigen
Created May 25, 2018 19:52
Show Gist options
  • Save mreigen/06b31846d5ed20056326df7fcd5a95d6 to your computer and use it in GitHub Desktop.
Save mreigen/06b31846d5ed20056326df7fcd5a95d6 to your computer and use it in GitHub Desktop.
Example of splitting a main routes file into smaller route files
Rails.application.routes.draw do
# ...
draw :v1
draw :v2
# ...
end
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
namespace :v1 do
namespace :auth do
# ...
end
# ...
resources :topics
# ...
end
namespace :v2 do
namespace :auth do
# ...
end
# ...
resources :topics
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment