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.

rake middleware not working in rails3 beta 3

#4492

I'm on rails 3 beta 3, and defined to use a middleware in environment.rb:

    MyApp::Application.configure do
       config.middleware.use '::ExceptionNotifier'
    end

    # Initialize the rails application
    MyApp::Application.initialize!

The middleware works fine. However, when I run rake middleware to see where it's sitting at, it is not mentioned in the list of middlewares. I also tried defining it within config.ru, no difference.

Reported by Lawrence Pit · April 28th, 2010 @ 12:19 AM

State: resolved
Milestone: 3.0.2
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. Jeremy Kemper
    Jeremy Kemper
    • Milestone cleared.
    • Assigned user set to José Valim

    April 28th, 2010 @ 12:38 AM

  2. José Valim
    José Valim

    The issue here is that rake tasks do not necessarily initialize your application. I.e. They load config/application but may not load config/environment or any of the initializers unless explicitly asked.

    That said, you should add the middleware to your app inside config/application.

    However there is always the chance this problem will happen in other circumtances, so the long term fix would make rake middleware always load the environment. The downside is the task becomes slower.

    Jeremy, wdyt?

    April 28th, 2010 @ 07:06 AM

  3. Lawrence Pit
    Lawrence Pit

    I've moved it to config/application.rb, and now I see the stack. Thnx.

    The reason I'd put it in environment.rb is because that's what's being advertised everywhere I looked (e.g. http://guides.rails.info/rails_on_rack.html and http://asciicasts.com/episodes/151-rack-middleware).

    I can imagine wanting middlewares that are only used within e.g. environments/development.rb. I think it would be good if you could see the complete stack then too. A slower task isn't an issue, displaying correct information is, imo.

    April 28th, 2010 @ 08:06 AM

  4. José Valim
    José Valim

    If you put in environments/development.rb it will still work. It won't work if you add them in any of config/initializers/* and config/environment.rb. And I totally agree that displaying correct information should be the priority.

    April 28th, 2010 @ 08:09 AM

  5. Jeremy Kemper
  6. José Valim
    José Valim

    Actually, rails was loading the environment, but rake tasks were doing it by itself (calling Rails::Application.initialize!) instead of loading the file at config/environment.rb. This was probably also the cause some rake tasks were loading the environment twice. A patch is coming soon.

    April 29th, 2010 @ 07:36 AM

  7. Repository
    Repository
    • State changed from new to resolved

    (from [1b816d502444ce2b3153d8c689d0057f1c257eee]) The rake task :environment now loads config/environment.rb instead of initializing the application on its own. This fixes [#4492 rake middleware not working in rails3 beta 3 state:resolved] and also avoids the application being initialized twice in some rake tasks. http://github.com/rails/rails/commit/1b816d502444ce2b3153d8c689d005...

    April 29th, 2010 @ 07:50 AM

  8. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to Low

    October 15th, 2010 @ 11:01 PM