How to install Paperclip

Paperclip is a plugin for Ruby on Rails’ ActiveRecord that lets files work as simply as any other attributes do. Installing Paperclip itself is simple and quick. But before you can use it, you have to install a couple of libs and softwares.

1. MacPorts

  The MacPorts Project is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11 or Aqua based open-source software on the Mac OS X operating system.

  Make sure Apple’s Xcode Developer Tools is installed (most of the developer would), you can find it at the Apple Developer Connection site or on your Mac OS X installation CDs/DVD. Download disk image from MacPorts offical site, double click the pkg file in the virtual disk to start installation. Notice:The installation may look like “hang up”, be patient, the “successful install” message will show up within five minutes. But you need to install more libs for MacPorts manually. Open Terminal application and type “sudo port -d selfupdate”, it will finish the rest.

2. ImageMagick

  ImageMagick® is a software suite to create, edit, and compose bitmap images. It can read, convert and write images in a variety of formats (over 100) including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF.

  This is what Paperclip based on. Installing ImageMagick via MacPorts is suggested. Open Terminal application and type “sudo port install ImageMagick”. The port command downloads ImageMagick and many of its delegate libraries (e.g. JPEG, PNG, Freetype, etc.) and configures, builds, and installs ImageMagick automagically. Notice: It will take such a loooooong time. In mainland China, connection to those sites of the libs is very very very slow. You will have to break the process by “ctrl+c” and redo “sudo port install ImageMagick” again and again. Fortunately, it will automatically resume the installation where you broke it.


3. RMagick


  RMagick is an interface between the Ruby programming language and the ImageMagick® and GraphicsMagick image processing libraries.

  Simply open Terminal application and type “sudo gem install rmagick”. Still you have to be patient. A lot of time will pass with no output from the gem command. The “Successfully installed” message does not mean that RMagick was successfully installed. The RMagick installation can encounter error conditions that gem can’t detect. The following irb session is a better indicator of a successful install. (Of course the version numbers in the message may vary from what is shown here, depending on what versions of the software are currently available.)



4. Paperclip

  This is the final stop of our trip.

  To install Paperclip, open Terminal application and type “script/plugin install git://github.com/thoughtbot/paperclip.git” at the root directory of your rails project. Creat your migration by typing “script/generate migration AddPhotoToListings”. Open your migration and add following:


  Then rake your migrations by “rake db:migrate”.

  Next you have to tell your model to use Paperclip, open app/models/listings.rb and add following:


  At new and edit views you can add:


  At show views you can add:

Now, enjoy Paperclip!

Posted by Billy Mon, 15 Jun 2009 15:41:00 GMT