This project is archived and is in readonly mode.

#4676 ✓wontfix
wildchild

Reload routes on each request in dev mode

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

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?

Comments and changes to this ticket

  • Ryan Bigg

    Ryan Bigg June 21st, 2010 @ 03:54 AM

    • State changed from “new” to “needs-more-info”

    Please provide a way to duplicate this bug.

  • José Valim

    José Valim June 22nd, 2010 @ 04:43 PM

    • 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).

  • Adam Williams

    Adam Williams January 13th, 2011 @ 07:17 PM

    • 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.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages