Paperclip Attributes Build Status Coverage Status

Rails Engine built on top of Paperclip gem to add attributes, as columns in your models, related to your attachments.


Add to your Gemfile:

gem "paperclip_attributes"
bundle install


To add new attributes, you need to run the following generator:

rails g paperclip_attributes Model attachment recipe1 recipe2
  • Model: is the Active Record model containing the attachment you want to add attributes.
  • attachment: is the paperclip's attachment name on given model.
  • recipes (recipe1 recipe2): is a list of recipes to extend the attachment. A recipe represents one or more attributes related to the attachment param. You can see a full list of recipes on the section below.

The generator, will only create migrations to extend your attachments. So, after run it, you need to do:

rake db:migrate

Then, to enable the functionality in your model, you need to add the recipes to the attachment definition:

class MyModel < ActiveRecord::Base
  has_attached_file :attachment, attributes: [:recipe1, :recipe2]

That's it!

The process to extract attributes will be done on before_save callback.


rails g paperclip_attributes User avatar dimensions color

In User model:

class User < ActiveRecord::Base
  has_attached_file :avatar, attributes: [:dimensions, :color]

Then, with an User instance, you'll be able to do something like this:

user =
user.avatar = some_file!

user.avatar_height #=> 200
user.avatar_width #=> 400
user.avatar_dominant_color #=> "#FF9900"


For images:


  • [attachment]_width: the original width of the image.
  • [attachment]_height: the original height of the image.


  • [attachment]_dominant_color: the predominant color of the image.


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request


Thank you contributors!


Paperclip Attributes is maintained by platanus.


Paperclip Attributes is © 2016 platanus, spa. It is free software and may be redistributed under the terms specified in the LICENSE file.