Skip to content

Instantly share code, notes, and snippets.

@revans
Forked from sharipov-ru/development.rb
Created February 25, 2016 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save revans/ffabacd251f7cd6f3f70 to your computer and use it in GitHub Desktop.
Save revans/ffabacd251f7cd6f3f70 to your computer and use it in GitHub Desktop.
config.middleware.use RoutesReloader
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
draw :people_and_groups
draw :projects
draw :calendars
draw :legacy_slugs
draw :ensembles_and_buckets
draw :globals
draw :monitoring
draw :mail_attachments
draw :message_preview
draw :misc
root to: 'projects#index'
end
# updated version of @shime's solution from https://gist.github.com/dhh/2492118
class RoutesReloader
ROUTES_PATH = Dir.glob("config/routes/*.rb")
def initialize(app)
@app = app
@routes_reloader = ActiveSupport::FileUpdateChecker.new(ROUTES_PATH) do
Rails.application.reload_routes!
end
end
def call(env)
@routes_reloader.execute_if_updated
@app.call(env)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment