Skip to content
mdarby edited this page Sep 12, 2010 · 17 revisions

Scribd_fu

A Ruby on Rails plugin that streamlines interaction with the Scribd service (scribd.com), and even works with Attachment_fu!

What it does

Scribd_fu hides out in the shadows like a document converting ninja, just waiting to process your data into a convenient Flash format (like YouTube) with the help of the black majick of Scribd.com. Imagine imbedding huge documents right inline with your web UI, no downloading, no necessary programs on the client side to view your data. It’s pretty damned cool.

Requirements

  1. Scribd_fu requires the wicked awesome Attachment_fu plugin. You probably already have it installed.
  2. You also need the rscribd gem (sudo gem install rscribd will do the trick)

How to Install

  1. Clone the git repository into your app’s vendor/plugins directory
    
    cd vendor/plugins && git clone git://github.com/mdarby/scribd_fu.git
    
  2. Install the rscribd gem
    
    gem install rscribd
    

How to Use

  1. Enter the below line into any attachment_fu-using model that you’d like to Scribdify
    
    acts_as_scribd_document
    
  2. Add the following fields into a new migration for the target model (and update your schema!):
    
    t.integer :scribd_id
    t.string :scribd_access_key
    
  3. Sign up for Scribd (it’s totally free)
  4. Copy the vendor/plugins/scribd.yml.example file to config/scribd.yml and fill out with your Scribd login credentials
  5. Now, when you upload a file that is convertible in the Scribd system, Scribd_fu will automatically handle the CRUD for you. No muss, no fuss.
  6. To view a Scribd document, just throw the below code into your view (where @document is an object of your Scribd/Attachment_fu model):
    
    <%= display_scribd(@document) %>
    </pre>

That’s it!

Example Model

This model has configured Attachment_fu to allow the uploading of PDF and plain text files. Attachment_fu will handle the uploading of the file and Scribd_fu will perform Scribd-related functions after the file is uploaded.


class Document < ActiveRecord::Base
has_attachment :content_type => [‘application/pdf’, ‘text/plain’],
:storage     => :file_system,
:path_prefix => ‘tmp/uploaded_files’,
:max_size    => 25.megabytes
validates_as_attachment
acts_as_scribd_document

end

Possible Errors

You need to fill in your name on your Scribd.com profile (http://www.scribd.com/people/edit) if you get an error like:


NoMethodError: You have a nil object when you didn't expect it!
The error occurred while evaluating nil.value
        from /usr/local/lib/ruby/gems/1.8/gems/rscribd-0.1.0/lib/scribdresource.rb:149:in `load_attributes'
        from /usr/local/lib/ruby/1.8/rexml/element.rb:891:in `each'
        from /usr/local/lib/ruby/1.8/rexml/xpath.rb:53:in `each'
        from /usr/local/lib/ruby/1.8/rexml/element.rb:891:in `each'
        from /usr/local/lib/ruby/1.8/rexml/element.rb:393:in `each_element'
        from /usr/local/lib/ruby/gems/1.8/gems/rscribd-0.1.0/lib/scribdresource.rb:145:in `load_attributes'
        from /usr/local/lib/ruby/gems/1.8/gems/rscribd-0.1.0/lib/scribduser.rb:35:in `initialize'
        from /usr/local/lib/ruby/gems/1.8/gems/rscribd-0.1.0/lib/scribduser.rb:127:in `new'
        from /usr/local/lib/ruby/gems/1.8/gems/rscribd-0.1.0/lib/scribduser.rb:127:in `login'
        from (irb):6

Further Info

You can make your Scribd documents private or public, to choose, just modify the scribd.yml file and enter ‘private’ or ‘public’ in the ‘access’ key.

About the Author

My name is Matt Darby. I’m a 28 year old professional Web Developer and IT Manager. I am the IT Manager and Lead Web Developer at Dynamix Engineering and recently earned a Master’s Degree in Computer Science from Franklin University in Columbus, OH.

Feel free to check out my blog or to recommend me

Clone this wiki locally