This project is archived and is in readonly mode.
in versions 2.3.X Configuration/Initialization problem when using config/environments/{xxx}.rb and config.plugins
Reported by Elias Baixas | March 8th, 2011 @ 05:54 PM
in rails-2.3.11/lib/rails/plugin/loader.rb method "plugins", the instance variable @plugins is cached (@plugins||= ...)
this method (plugins) is called from within the add_plugin_load_paths as seen in this backtrace:
"/opt/local/lib/ruby/gems/1.8/gems/rails-2.3.11/lib/rails/plugin/loader.rb:24:in
plugins'",
"/opt/local/lib/ruby/gems/1.8/gems/rails-2.3.11/lib/rails/plugin/loader.rb:56:in
add_plugin_load_paths'",
"/opt/local/lib/ruby/gems/1.8/gems/rails-2.3.11/lib/initializer.rb:294:in
add_plugin_load_paths'",
"/opt/local/lib/ruby/gems/1.8/gems/rails-2.3.11/lib/initializer.rb:136:in
process'",
"/opt/local/lib/ruby/gems/1.8/gems/rails-2.3.11/lib/initializer.rb:113:in
send'",
"/opt/local/lib/ruby/gems/1.8/gems/rails-2.3.11/lib/initializer.rb:113:in
run'",
"/Users/elias/src/ruby/prueba/config/environment.rb:23",
since "add_plugin_load_paths" is called before "load_environment" in Rails::Initializer.process:
def process
Rails.configuration = configuration
check_ruby_version
install_gem_spec_stubs
set_load_path
add_gem_load_paths
require_frameworks
set_autoload_paths
add_plugin_load_paths
load_environment
if one is to configure plugin loading order, and maybe prevention of plugin load, the caching of @plugins before "load_environment" renders config.plugins useless if they were set in config/environments/{production,development,test}.rb.
this renders all the config.plugins functionality useless, since (in my POV) the main use of config.plugins is to enable or disable some plugins in Production or Development.
This would be fixed just by moving load_environment before add_plugin_load_paths in Rails::Initializer.process.
to reproduce this issue, just do (with rails 2.3.X with X upto 11):
rails prueba
cd prueba
script/plugin install git://github.com/abedra/safe-erb
echo "config.plugins=[]" >>
config/environments/production.rb
echo "config.plugins=[:"safe-erb"] >>
config/environments/development.rb
script/generate scaffold post body:text title:string
RAILS_ENV=production rake db:migrate
RAILS_ENV=development rake db:migrate
now
RAILS_ENV=production script/server
and navigate to localhost:3000/posts and see how the plugin was loaded (since safe-erb prevented outputting some strings)
then
RAILS_ENV=production script/console
Rails.configuration.plugins shows []
but it is wrong, since the plugin was actually loaded.
Comments and changes to this ticket
-
Elias Baixas March 8th, 2011 @ 06:00 PM
the solution offered in the Ticket is wrong (just tried it :P), when I find some other solution, I'll post it.
-
Elias Baixas March 8th, 2011 @ 06:08 PM
Sorry once again: the solution offered was indeed right (I had other troubles with my plugins).
-
Anuj Dutta March 9th, 2011 @ 06:58 AM
- State changed from new to invalid
- Importance changed from to Low
Marking it invalid.
-
Anuj Dutta March 9th, 2011 @ 10:12 AM
@Xavier - I thought that was self-explanatory since the person who added the ticket realised the error was due to some other issues with the plugin.
-
Xavier Noria March 9th, 2011 @ 10:18 AM
@Anuj, oh, Elias said in the last comment that the solution is right indeed. The issue with plugins explained why he tought it was wrong in the first comment :).
2-3-stable is mostly frozen anyway, only security fixes and the-universe-is-gonna-collide bug fixes.
I guess the underlying issue is that Rails does not provide a way to configure plugins per environment. This could be perhaps be converted to a feature request for master.
-
Anuj Dutta March 9th, 2011 @ 10:33 AM
@Xavier: Gotcha! Sorry, I should pay more attention before wielding invalid ticket. But would Bundler not solve the same issue.
-
Xavier Noria March 9th, 2011 @ 10:39 AM
@Anuj, indeed Bundler provides that for gems, but not for plugins.
-
Anuj Dutta March 9th, 2011 @ 10:49 AM
- State changed from invalid to open
- Assigned user set to Anuj Dutta
@Xavier: Yeah, true.
I will mark this ticket as open and assign it to myself and explore the possibilities with using bundler and update the ticket accordingly which will result in a resolution either way.
Apologies again for acting quickly before thinking.
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>