How to Convert Simple Rails 2.3 Style Plugins for Rails 3.2
Upon updating your older project to Rails 3.2, one of the first things you will see is a deprecation notice in your logs:
Your first thought might be to just rewrite this yourself and get rid of this circa-2006 code anyway, but the lazy sloth in you says "if it ain't broke, don't fix it" so you google for the easy solution... landing here. This post will show you how to quickly convert your simple old-school plugins into simple libs per the Rails 3.2 Release Notes. This might not work for crazy-advanced-super-plugin-eleventeen-point-oh, but for the simple ones it should suffice.
- Inspect your
vendor/plugins
directory. If your old plugin has some crazy-ass structure that doesn't look anything like this, you are on your own. Google for another page or press on at your own risk. - Rename the
lib
folder to the name of the plugin. When you move it in the next steps, this will help you stay organized. - Rename the
init.rb
file into the name of your plugin. When you move it in the next steps, this will also help you stay organized. - Move the folder you renamed in step 2 to the main project's
lib
directory. Now the rename makes sense. Alib
folder with a nestedlib
folder is a naming nightmare.
- Move the file you renamed in step 3 to the main project's
config/initializers
directory. Again, nobody wants to see aconfig/initializers/init.rb
file, hence the rename. - Inspect the initializer file.There are probably some weird requires and other lines here that might need your attention. Look for obvious path errors and fix them. For my old-school can_flag plugin, I had to change the single
require
to the explicitly require the files in thelib/can_flag
directory - Delete the crap from
vendor/plugins
. You could do something else with the tests folder and integrate the plugin's other files into your app, but since you were using antiquated old-school plugins already, chances are you aren't really concerned with that shit anyway. The new plugins folder structure should be bare. - Test it out in rails console. The first thing you should notice is the lack of the deprecation notice anymore. Then a simple test should tell you if you were successful.
You will have to make sure you didn't fuck anything up, but for my simple plugins, this process was enough.
Was this page helpful for you? Buy me a slice of 🍕 to say thanks!
Comments