Matt Coneybeare

MC

How to Convert Simple Rails 2.3 Style Plugins for Rails 3.2

| Comments

Upon updating your older project to Rails 3.2, one of the first things you will see is a deprecation notice in your logs:

1
You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this:http://weblog.rubyonrails.org/2012/01/04/rails-3-2-0-rc2-has-been-released

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.

  1. 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.

  2. Rename the lib folder to the name of the plugin. When you move it in the next steps, this will help you stay organized.

  3. 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.

  4. Move the folder you renamed in step 2 to the main project’s lib directory. Now the rename makes sense. A lib folder with a nested lib folder is a naming nightmare.

  5. Move the file you renamed in step 3 to the main project’s config/initializers directory. Again, nobody wants to see a config/initializers/init.rb file, hence the rename.

  6. 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 the lib/can_flag directory

  7. 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.

  8. 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.

Comments

My name is Matt Coneybeare, I design and develop for iOS (iPhone, iPad and iPod Touch), Mac OS X and the Web out of New York. In 2008 I started a software company called Urban Apps that has made some pretty popular apps such as Ambiance and Hourly News. My current Stack Overflow reputation is about 21k.

I was a Rockstar a decade ago, but then went back to school and collected a Bachelor's Degree in Computer Science from U.C. Berkeley. Now I am settled down with my beautiful wife Di and our three doggies Hamachi, Foxy and Millie. While coding, I walk at least 16 miles/day on my Treadmill Desk. When not at my desk, I love exploring New York City as a Yelp Elite.

Contact information

Name
Matt Coneybeare
Email
Website
Twitter
App.net
Instagram
GitHub
Wizpert
Google+