Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Reload routes on each request in dev mode

#4676

If some modules or classes has state which populated by custom mapper (just like devise does) its state will never be populated next time the module is reloaded. Currently the one and only workaround is to $ touch config/routes.rb, but quite annoying. Thoughts?

Reported by wildchild · May 23rd, 2010 @ 09:18 PM

State: wontfix
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Ryan Bigg
    Ryan Bigg
    • State changed from new to needs-more-info

    Please provide a way to duplicate this bug.

    June 21st, 2010 @ 03:54 AM

  2. José Valim
    José Valim
    • State changed from needs-more-info to wontfix

    Loading routes in all requests can hit performance hard, so it's a no go about this (note: I'm Devise core developer).

    June 22nd, 2010 @ 04:43 PM

  3. Adam Williams
    Adam Williams
    • Importance changed from to Low

    I hope this is an appropriate place to bring this up...

    Since the routes are only reloaded when the mtime of the file has changed, any auto-loaded constants referenced in the routes file are not 'replaced' when their source file is reloaded after Dependencies.clear.

    For instance:

    match '/abc' => MyAutoloadedEndpoint
    

    When Dependencies.clear has been run, and I have modified the source for MyAutoloadedEndpoint, things get weird. The constant is no longer defined, but the route set is still referencing that old code. If the call method of the endpoint then causes an auto load of another class, const_missing attempts to resolve it by utilizing a nesting process that will then auto load MyAutoloadedEndpoint!

    Am I off my rocker? I have solved this for myself by adding, in an config/initializer/endpoints.rb, this bit of code:

    if Rails.env == "development"
      lib_reloader = ActiveSupport::FileUpdateChecker.new(Dir["app/endpoints/**/*"], true) do
        Rails.application.reload_routes!
      end
    
      ActionDispatch::Callbacks.to_prepare do
        lib_reloader.execute_if_updated
      end
    end
    

    I'd love you're feedback, or pointers on where to talk about this. Thank you.

    January 13th, 2011 @ 07:17 PM