This project is archived and is in readonly mode.
rake middleware not working in rails3 beta 3
Reported by Lawrence Pit | April 28th, 2010 @ 12:19 AM | in 3.0.2
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.
Comments and changes to this ticket
-
Jeremy Kemper April 28th, 2010 @ 12:38 AM
- Milestone cleared.
- Assigned user set to José Valim
-
José Valim April 28th, 2010 @ 07:06 AM
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?
-
Lawrence Pit April 28th, 2010 @ 08:06 AM
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.
-
José Valim April 28th, 2010 @ 08:09 AM
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.
-
José Valim April 29th, 2010 @ 07:36 AM
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.
-
Repository April 29th, 2010 @ 07:50 AM
- 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 state:resolved] and also avoids the application being initialized twice in some rake tasks. http://github.com/rails/rails/commit/1b816d502444ce2b3153d8c689d005...
-
Jeremy Kemper October 15th, 2010 @ 11:01 PM
- Milestone set to 3.0.2
- Importance changed from to Low
-
csnk May 18th, 2011 @ 08:25 AM
We are the professional uniforms manufacturer, uniforms supplier, uniforms factory, custom uniforms.
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>
People watching this ticket
Tags
Referenced by
- 4492 rake middleware not working in rails3 beta 3 (from [1b816d502444ce2b3153d8c689d0057f1c257eee]) The rak...