How to config plugin classes in dev/test/prod env file
Dorren_mii_thumb by dorren, 10/02/2007
Most of plugins set initial configuration values in default environment.rb file. What if you've written a plugin, and you want to set different config values in each environment, in RAILS_ROOT/config/environments/XXX.rb? You can't do that directly.

For example, If you have a Widget class in your plugin, and you want to set Widget.param=123 in test.rb, what you get is a big fat class not found error, like
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:266:in `load_missing_constant': uninitialized constant Widget (NameError)
The reason for that is when rails is starting up and processing each environment file, it hasn't load any plugins yet, so it doesn't know about your plugin classes. When I searched the web for solutions, people tried modifying rails initializer or other similar crazy stuff.

The solution is quite simple, just do it afterwards.

at the end of my environment.rb, just add require File.join(File.dirname(__FILE__), "environments/#{ENV['RAILS_ENV'] || 'test'}_post_init")
"|| 'test'" part is need for rake. then put your plugin configuration code in environments/test_post_init.rb, development_post_init.rb, and production_post_init.rb

If any of the config values are used in config/routes.rb, make sure to copy that line in the beginning of routes.rb file too.

Views: 1463   Replies: 0   Tags: plugin

comments

 
login or sign up to participate.




Money_dollar moneywill