How to create a plugin no comments
Create a plugin on rails is the best way to share a features or a code between applications and with others. I found a lot information about how to extend or mixin ActiveRecord, but no information about how to provide a piece of application. Maybe I do wrong but that’s how I did:
The more completed information is on Rick Olson blog, not in the plugin initialization :), but in the initialization process part I. The installation process has changed with Rails 1.2.
The work with model can be simple, you can put a require in your init.rb and your model will be available for the application.
In my case I need to make available a whole piece of application with models, views and controller. the way to do (from techno weenie):
for your model :
models_path = File.join(directory, 'app', 'models')
$LOAD_PATH << models_path
Dependencies.load_paths << models_pathfor the controllers it’s quite the same:
controller_path = File.join(directory, 'app', 'controllers')
$LOAD_PATH << controller_path
Dependencies.load_paths << controller_path
config.controller_paths << controller_pathIt’s very important to register controllers this way, else they will not be recognized for routing.
And finally to include views, you should integrate in your controller:
self.template_root = File.join(File.dirname(__FILE__), '..', 'views')to make views available for your controller.
Once you have that, your application plugin is ready to be used in another application.
Now, I have many questions:
- Is it the good way to share a piece of application?
- How standardize the way of communicate between application and plugin ?
- In the same topic, I have 2 parts in the plugin, one for admin and one for front user, How should I do to easily provide a plugin knowing every application have a different way to authorize or authenticate users?
Please feel free to share any knowledge on these subjects :)
I will update this post later because have some other steps to include like migration and dispatching.




