Scribd_fu Paperclip goodness

So over the past month or so I refactored Matt Darby's awesome scribd_fu plugin ( to work with Paperclip in addition to attachment_fu. I'm more a fan of Paperclip, as it turns out, and had been meaning to switch OpenStudy to Paperclip. Well, I finally got around to doing both, but then I sat on my code for a little while before working on merging it back into mdarby's main repository.

First lesson learned: before you start a crazy refactoring job, make sure to pull from the repository you forked. At least if you intend on merging back. Turns out, when I started hacking, the main scribd_fu repository was about 8 commits ahead of mine. I realized this about 10 commits into mine, at which point I was past the point of no return. I finished up my refactoring, and, over the last week or so, I merged the changes from the main repository back into the newly refactored code, making it work for both attachment_fu and Paperclip. All in all, it was a fun exercise in `think before you start hacking'.

Still, the end result is sexy: installing the mdarby-scribd_fu gem from github will work happily, and you can use config.gem from Rails 2.1+ to delightfully have that taken care of for you. Meantime, it ensures that the rscribd gem is present, as well. Plus, it automatically figures out whether you are using Paperclip or attachment_fu and behaves accordingly.

One thing to note is that, since you are installing from, the rscribd dependency will only be resolved automatically if you have in your Rubygems sources and do a

  $ gem install mdarby-scribd_fu

If you include a --source directive, things won't go so well, and you will instead get this nasty bugger:

 $ sudo gem install mdarby-scribd_fu --source
  ERROR:  Error installing mdarby-scribd_fu:
        mdarby-scribd_fu requires rscribd (>= 0, runtime)

Icky! Anyway, if you'd rather not add github to your sources, then go ahead and install the rscribd gem manually first. If you still want to use config.gem, just make sure to config.gem 'rscribd' before mdarby-scribd_fu.

A few notes about the release:

* The old acts_as_scribd_document method should continue to work without your doing anything if you use attachment_fu.
* Optionally, you can switch to the has_scribdable_attachment method with no parameters for attachment_fu.
* When using Paperclip, you have to use has_scribdable_attachment and pass it the attachment that should be sent to scribd for conversion as a symbol.
* Validations now work. Before, uploads happened after_save, and validations relied on results that came only after the upload took place (e.g., the presence of scribd_id). Now the upload is run before_validation, so that the validations have the data available. The price for this is that an extra temporary file may have to be created to execute the upload.

All Paperclip-related methods take the scribdable attachment as a symbol. In the case of the view helper, the attribute is the second parameter. This gives the scribd_document method two forms:

* scribd_document(model, alternate_text) for attachment_fu and
* scribd_document(model, attachment, alternate_text) for Paperclip.

The alternate_text can be left off for both.

I haven't had a chance to really hammer this thing with tests, though my limited testing does show that it works just spiffily. Any bugs can be reported by listing them on the scribd_fu wiki ( Enjoy, and let us know about problems!