FileColumn to Paperclip Migration

Like so many people, when moving from Rails 2 to Rails 3, I found myself migrating from using FileColumn (i.e. file_column) to Paperclip, for image-upload handling in rails. I found an excellent migration guide written by Mark Cornick.

The general process is:

  1. Install Paperclip.
  2. Generate a migration to add the Paperclip-controlled image to your model. This adds a few Paperclip columns to the model’s table.
  3. Update your model code to use Paperclip.
  4. Update your views to use Paperclip’s method for writing the images, and Paperclip’s method for writing the fields for uploading the images.
  5. Write a migration that does the leg-work of moving your images from FileColumn to Paperclip.
  6. Uninstall FileColumn.

Step #5 is the most complex bit. There’s a few things that your migration has to do:

  1. Rename/restructure directories where FileColumn stored images to the new Paperclip way. e.g. directory names are singular in FileColumn, plural in Paperclip.
  2. Rename/move actual images to the new Paperclip-expected locations. e.g. different image styles (e.g. original, thumbnail, etc.) differ between FileColumn and Paperclip.
  3. Populate the new Paperclip table columns with data about the images.

Mark shared a Gist that showed did all these, except for a couple of issues: It didn’t handle varying image styles (e.g. original, thumbnail, etc.), and it wasn’t a reversible migration. Using Mark’s migration as a starting point, I added support for styles, and made it reversible*. You can see my fork as a Gist. I hope someone finds it useful.

* The “reversible” comes with caveats: I’ve tried to write it in such a way that it will recover from a failed forward migration, but testing rolling back from every possible point of failure would be onerous. It works reliably if the whole forward migration succeeds, and the resulting DB contents and file structure match the beginning point. Empty Paperclip directories are not deleted after rolling back. You should back-up your database before trying it.

Hanzi Challenge – Mac OSX Dashboard Widget

I have an Android desktop widget that shows me a random Chinese word when I look at my phone’s home screen. I really wanted this functionality on my laptop, so I wrote a simple Dashboard Widget that shows a random Hanzi word when I open the Dashboard. It’s called “Hanzi Challenge”, and you can grab it from my web site.

Hanzi Challenge Dashboard Widget Screenshot.

It shows you the word (in simplified or traditional characters; your preference) and displays the Pinyin pronunciation as a clue when you mouse over it. Click to see the English translation.

LibrarySearch – Public Library Search From Your Browser

I’m a bit of a miser when it comes to books; I haven’t made the switch from physical books to digital ones, and I don’t think I will any time soon. Partly, it’s because I get all my books from the library.

While the public library has its own search web site, it lacks the recommendations capabilities of sites like Amazon, or Goodreads. To make it easier to find the books I want, I wrote an extension that lets me select some text in a browser, and search for it in my public library:

It works from any web page, and is now available as both a Chrome extension, and a Safari one. (Firefox coming soon).

The Chrome version is available on the Chrome Web Store. You can download and install the Safari one from the LibrarySearch page on my site.