ruby-on-rails

Paperclip and ImageMagick for images in Rails

Follow me
Follow me

Latest posts by Tomasz Antas (see all)

May 7, 2015

Paperclip is a Rails gem which allows to upload and manage images. It requires ImageMagick library to work.

 

 

 

ImageMagick installation

Use following commands to install ImageMagick on Ubuntu:

More information about ImageMagick you can find on official website.

 

Paperclip installation

Paperclip is a Rails gem. Add to Gemfile:

And run bundler:

 

Paperclip usage

Paperclip allows to add easily the image feature to any model. For example, we can add Logo to Restaurant model:

This command will generate migration, which we need to run:

In model (in our case is Restaurant) add few settings and validation:

You can also set up pathurl and few others. See more on GitHub.

You may need to add also to config/environments/development.rb:

Below are short examples how to use images in different views:

New/Edit View

 

Show View

 

 

 

 

 

Tomasz AntasPaperclip and ImageMagick for images in Rails