This project is archived and is in readonly mode.
rake middleware not working in rails3 beta 3
-
Jeremy Kemper
- Milestone cleared.
- Assigned user set to 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?
-
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.
-
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.
-
Jeremy Kemper
+1 to loading the env
-
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.
-
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...