Rails Engine built on top of Paperclip gem to add attributes, as columns in your models, related to your attachments.
Add to your Gemfile:
To add new attributes, you need to run the following generator:
rails g paperclip_attributes Model 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:
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] end
The process to extract attributes will be done on
rails g paperclip_attributes User avatar dimensions color
class User < ActiveRecord::Base has_attached_file :avatar, attributes: [:dimensions, :color] end
Then, with an
User instance, you'll be able to do something like this:
user = User.new user.avatar = some_file user.save! user.avatar_height #=> 200 user.avatar_width #=> 400 user.avatar_dominant_color #=> "#FF9900"
[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.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- 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.