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.

in versions 2.3.X Configuration/Initialization problem when using config/environments/{xxx}.rb and config.plugins

#6545

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:inadd_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:inprocess'", "/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:inrun'", "/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.

Reported by Elias Baixas · March 8th, 2011 @ 05:54 PM

State: open
Milestone: none
Assigned to: Anuj Dutta Anuj Dutta
Importance: Low

Activity

  1. Elias Baixas
    Elias Baixas

    the solution offered in the Ticket is wrong (just tried it :P), when I find some other solution, I'll post it.

    March 8th, 2011 @ 06:00 PM

  2. Elias Baixas
    Elias Baixas

    Sorry once again: the solution offered was indeed right (I had other troubles with my plugins).

    March 8th, 2011 @ 06:08 PM

  3. Anuj Dutta
    Anuj Dutta
    • State changed from new to invalid
    • Importance changed from to Low

    Marking it invalid.

    March 9th, 2011 @ 06:58 AM

  4. Xavier Noria
    Xavier Noria

    Would be nice to explain why the ticket is invalid.

    March 9th, 2011 @ 08:33 AM

  5. Anuj Dutta
    Anuj Dutta

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

    March 9th, 2011 @ 10:12 AM

  6. Xavier Noria
    Xavier Noria

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

    March 9th, 2011 @ 10:18 AM

  7. Anuj Dutta
    Anuj Dutta

    @Xavier: Gotcha! Sorry, I should pay more attention before wielding invalid ticket. But would Bundler not solve the same issue.

    March 9th, 2011 @ 10:33 AM

  8. Xavier Noria
    Xavier Noria

    @Anuj, indeed Bundler provides that for gems, but not for plugins.

    March 9th, 2011 @ 10:39 AM

  9. Anuj Dutta
    Anuj Dutta
    • 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.

    March 9th, 2011 @ 10:49 AM

  10. Xavier Noria
  11. bingbing