Migrating from attachment_fu to paperclip
Thoughtbot have released a suite of plugins over the past few months that are enlivening the fields of Ruby on Rails file attachments (paperclip) and authentication (clearance), long dominated by Rick Olson’s attachment_fu and restful_authentication. You can see some previous posts about attachment_fu here and here.
I’ve been playing with paperclip on a couple of projects, including one which was previously using attachment_fu. That necessitated some work migrating the previous attachments. Opinions are divided on whether data should be transformed in migrations or in separate libraries, and I’d rather remain agnostic on that, but I whipped together some code that can be used either in migrations or an external library to make the transfer.
To use it, do something like:
class ConvertAvatar < ActiveRecord::Migration include PaperclipMigrations def self.up add_paperclip_fields :users, :photo User.reset_column_information User.all.each do |user| populate_paperclip_from_attachment_fu(user, user.avatar, 'photo') if user.avatar end end end
It’s quick and a little dirty, but it’s done the job for me. If you’re using S3 for storage, you might prefer to check out Andrew Timberlake’s writeup.
Delayed Job dying silently
about 1 month ago - No comments
I’ve just completed migrating a client site from BackgrounDRb to delayed_job (which is a huge relief on several levels). I had hoped to complete the process this morning, but the delayed_job process kept dying on me without any apparent explanation in the usual logs. Thankfully the RPM log in my app turned out to be More >
Character encodings, Rails 3 and Ruby 1.9.2
about 3 months ago - No comments
In a lengthy blog post detailing many of the intricacies and some of the politics relating to character encodings in Ruby, Yehuda Katz has a few paragraphs that left me more than a little excited: The most common scenario where you can see this issue is when the user pastes in content from Microsoft Word, More >
has_many_polymorphs and Rails 3
about 3 months ago - 2 comments
I’m gradually porting a number of my older Rails apps over to Rails 3. The main motivation is a chance to really put the new version through its paces, get a better sense of how it’s working, where plugins are at, etc; but it’s also rather nice to get some of the performance improvements and More >
Asset bundling in Rails
about 3 months ago - No comments
I stumbled across James Herdman’s piece on asset bundling in rails earlier this week. I’d always presumed you could do this but never got round to investigating as very few of my projects load in very large numbers of JS/CSS assets. In the end it was quite timely as I’ve been trying to reduce the More >
Faster Rails development with bundler and rvm
about 4 months ago - 2 comments
If you’re anything like me, you’ve found the rails server and console taking longer and longer to launch lately. Even switching to Rails 3 for most active projects hasn’t really helped. But I finally found a solution a couple of weeks ago. I found it reading Mikel Lindsaar’s Bundle Me Some Sanity where he outlines More >
More notes from a Rails 3.0pre upgrade
about 8 months ago - Comments Off
This is a follow-on from my piece on how I got the (development version of) Catapult Magazine up and running with Rails 3.0pre. If you haven’t already done so, I’d recommend you read that first. Catapult makes use of the permalink_fu plugin which fails in Rails 3. It fails because of a reliance on the More >
Upgrading an app to Rails 3.0pre
about 8 months ago - 1 comment
I used to be a strong adherent to tracking edge rails. Up until the release of rails 2.3 I let most of my frequently updated projects track edge with a vendored copy of rails, and it rarely caused me any trouble. When 2.3 hit I rethought all that. With Rails 3 development ramping up I More >
Rails 2.3 final and theme_support updates
about 1 year ago - Comments Off
Somewhere between Ruby on Rails versions 2.3.0 (RC1) and 2.3.2 (final) a change was made to the arguments required for one of the methods the theme_support plugin requires. I must confess I hadn’t spotted it, but github user knapo kindly sent me a message with a patch. That patch is now applied in the main More >
Rails 2.3 and theme_support part 3: Layouts
about 1 year ago - 11 comments
In my ongoing efforts to bring my fork of theme_support in line with Rails 2.3 I’ve covered the core views and email, but when I left off earlier today layouts still weren’t working. The key problem with overriding layouts is that the process of identifying them relies on some class methods on ActionController::Base (provided in More >
Rails 2.3 and theme_support part 2: ActionMailer
about 1 year ago - 6 comments
Stage 2 of fixing up theme_support for Rails 2.3 was making sure that ActionMailer picked up themed templates (for stage 1 information see here). That’s something I’d not quite cracked in the 2.2 version, so starting afresh with 2.3 forced me to spend the time to look through the full render path and figure out More >
Comments are closed.
about 1 year ago
James, nice writeup. Thanks for mentioning my post.
about 1 year ago
So how do you like paperclip? And do you prefer clearance to restful-authentication?
about 1 year ago
So far I’m really liking them both.
A lot of the elegance of paperclip is lost if you’re working with models that have many images, but for the (very frequent) cases where I just have one image per model (eg. user avatars) it’s simplified my code a lot.
I’ve not spent as much time with clearance, but it’s main appeal to me is the strong focus on tests. I’ve spent far too much time trying to work around the auto-generated specs that come with restful-auth. I also like that it comes with password retrieval code, as that’s usually a bit of a time-sink (or requires yet another plugin) when using restful-auth.
about 1 year ago
Have you tried authlogic?
We’ve been really happy with it so far.
http://github.com/binarylogic/authlogic/tree/master
about 1 year ago
David – I’ve been looking at authlogic but not tried it yet. I really like the use of a Session model, and just need some time to play with it.
about 1 year ago
Thank you so much for this! It was a life saver on a recent upgrade from rails 1.2 to 2.3!