Another look at integrating Scribd with your Rails application

Almost a year ago I wrote about integrating Scribd into your Rails application, and since then that feature has been working well in my applicant tracking system. Today, though, I got a request for information on how I display the documents that I send to Scribd, so I thought I'd share that, too.

In the previous post I showed how to send the document to Scribd using the API, and in this post I'll show how I take the results from the API and use them in my application. First, here's a snippet from my Attachment model that shows I create Scribd URLs based on the info that comes back from the API. The scribd_access_key and scribd_doc_id are database-backed methods whose values get populated with the response from the API. The scribd_url method is defined like so, simply creating a link to Scribd using the document ID and access key:

Here's a snippet from my view that shows the attachments related to a job candidate's submission. The preview link is conditional on the Scribd document ID being set, since not all documents that could be attached (e.g., resumes in WordPerfect format) will be successfully converted by Scribd. The user still gets a download link though.

And here's my javascript that I inject into the head of the document via that call to content_for. It takes the info from the preview link and passes that along to the javascript provided by Scribd for doing in-page embedding.

So there you go, a complete Scribd integration for Rails, both server-side and client-side. Now it should be as easy as pie for you to bake Scribd into your own application.

Comments