Rails plugins that use other plugins - why is does this seem impossible?

OK, probably the most frustrated I've ever been with Rails. If I don't figure this out, I'm going to, um... try again tomorrow.

I'm simply trying to create a plugin. I did the ./script/generate plugin MY_NEW_PLUGIN and wha-hoo great! Well, not really...

This plugin uses other plugins. For example, acts_as_list, acts_as_money etc.. How the heck to I get these plugins loaded and ready to be used? I've put them here:

main-app/vendor/plugins/MY_NEW_PLUGIN/vendor/plugins/

I've added all of their paths and lib paths to the config.load_paths variable, I've tried loading (require and load) their init.rb files. And no matter what, it's pretty obvious that the paths aren't setup correctly. I've even tried

$: << 'path/to/acts_as_list' $: << 'path/to/acts_as_list/lib'

I'd like to be able to specify additional load_paths in init.rb and then use config.plugins - seems logical.?

Ahhhhhhoar!!!

perhaps just a require ‘acts_as_list’ with a rescue with an error message will do it, probably. There’s most likely a better way to go about it, and why not ask the #rubyonrails irc channel in irc.freenode.net? Their responses can be more instantaneous than here most times.

Hi Ryan,

I tried irc, which is totally foreign to me. What is nickserv? Am I supposed to signup for membership?

perhaps just a require 'acts_as_list' with a rescue with an error message will do it, probably.

Well, my plugin, will come with acts_as_list. So I just want to be able to load it correctly. When my plugins init.rb file is loaded, I'm pretty sure that $LOAD_PATH is already set. So using config.load_paths doesn't seem to do anything. And the same with config.plugin_paths.

Oh yeah I should’ve mentioned. You have to have a registered name before you go into the channel so that random people can’t spam it. Just type /msg nickserv help register and follow the instructions.

Cool, thank you :slight_smile:

Is this rails 1.2 or rails 2.0? Quite a bit changed about plugin loading in between.

Fred

Rails 2.0.2

I found a way to make it all work - not the correct, Rails way though. It's not what I would have expected. I thought I could do everything I needed inside of the init.rb file. But from the way it seems, at that point it's too late to add to the $LOAD_PATH so adding plugins to config.plugins inside of init.rb doesn't work. Or am I wrong? I tried many different things.

I'll come clean now; this plugin is really another Rails app. it has controllers, models, views, routes etc.. I wanted to be able to reuse this inside of client apps. And maintain only one code base for the "plugin" (updatable via svn etc.) I wanted it to work like Django apps do. And I achieved a lot of that by initializing my plugin inside of the Rails::Initialize.run block:

Rails::Initialize.run do |config|   MySuperPluginThatsReallyAnApp::init(config) end

Basically, I add a bunch of paths (load_paths and load_once_paths), include my plugins etc.. Now I can use that one line in my main apps' environment.rb file, and without doing anything have a full blown app running without doing any extra coding. And thanks to the load paths, I can override any view, model etc.. just by creating the file in the app that's using the "plugin". Very handy. I have to manually copy routes, and public folder items, but that's OK. I want to be able to override those aspects anyway.

The big downside is that I can't do cool, builtin things with Rake, and testing. So I'm going to keep trying to get this to work the correct, Rails 2.0 plugin way.

Feedback anyone?