I should add.. this fix (self.code_paths instead of
Rails[:plugin_name].code_paths) seemed to make it not crash and did store
the path in Rails.plugins[:plugin_name]. But, it just didn't work. I
eventually traced it down to the fact that rails adds plugin paths *before*
engines is loaded.
/usr/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb ln ~60
# Sequentially step through all of the available initialization
routines,
# in order:
#
# * #check_ruby_version
# * #set_load_path
# * #require_frameworks
# * #set_autoload_paths
# * add_plugin_load_paths ********** plugin code_paths are added to
Dependencies.load_paths here
# * #load_environment
# * #initialize_encoding
# * #initialize_database
# * #initialize_logger
# * #initialize_framework_logging
# * #initialize_framework_views
# * #initialize_dependency_mechanism
# * #initialize_whiny_nils
# * #initialize_temporary_directories
# * #initialize_framework_settings
# * #add_support_load_paths
# * #load_plugins ********* but plugins are loaded here
# * #load_observers
# * #initialize_routing
# * #after_initialize
# * #load_application_initializers
def process
Actually, this seems like a rails bug in itself. Or maybe it's that way by
design? In either case, it will break your code_paths done in a plugin's
initialize. Here's a patch for engines loader (again which doesn't seem to
really belong in engines.. but it already has the loader overridden..)
vendor/plugins/engines/lib/engines/plugin/loader.rb
module Engines
class Plugin
class Loader < Rails::Plugin::Loader
+ def load_plugins
+ super
+ add_plugin_load_paths
+ end
+
protected
def register_plugin_as_loaded(plugin)
super plugin
Engines.plugins << plugin
register_to_routing(plugin)
end
# Registers the plugin's controller_paths for the routing system.
def register_to_routing(plugin)
initializer.configuration.controller_paths +=
plugin.select_existing_paths(:controller_paths)
initializer.configuration.controller_paths.uniq!
end
end
end
end
-Andrew
On Dec 27, 2007 12:07 AM, Andrew Roth <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I have some code in a plugin's init.rb that used
> Rails.plugins[:plugin_name].code_paths
> += ... I spent a bit of time hacking engines to get it working, then I read
> Sven's helpful message at
> http://www.ruby-forum.com/topic/135196#602078(essentially "Contrary to Rails
> 1.2.x the init.rb file is now evalutated inside of the Plugin object." and
> just use code_paths += ...)
>
> Btw, I had to use self.code_paths +=, not code_paths by itself. Is that
> expected?
>
> > "Hmm, we probably should put that into some kind of upgrade note. Or
> even
> > a rake task that goes through the init.rb files and removes those bits
> like
> > Rails.Engines[:name]? But maybe that's not worth the hassle?"
>
> Yes definitely a message on how to migrate from 1.2.x to 2.x engines. The
> rake tast is probably not necessary imo, we are used to reading the messages
> and making appropriate changes.
>
> Anyways I thought I would include my changes in case someone finds them
> useful. Definitely changing Rails.plugins[:plugin_name] to self is the
> better way. But maybe someone will need to use this way for some reason.
>
> -Andrew
>
> http://svn.rails-engines.org/engines/trunk/lib/engines/plugin.rb
>
> # Extends the superclass' load method to additionally mirror public
> assets
> def load(initializer)
> return if loaded?
> +
> + # add plugin before calling initializer and anything else since
> this seems
> + # to be the expected behavior
> + Engines.plugins << self
> +
> super initializer
> add_plugin_view_paths
> Assets.mirror_files_for(self)
> end
>
> http://svn.rails-engines.org/engines/trunk/lib/engines/plugin/loader.rb
>
> def register_plugin_as_loaded(plugin)
> super plugin
> - Engines.plugins << plugin
> register_to_routing(plugin)
> end
>
>
>
_______________________________________________
Engine-Developers mailing list
[email protected]
http://lists.rails-engines.org/listinfo.cgi/engine-developers-rails-engines.org