No commit activity in last 3 years
No release in over 3 years
The pre-defined variants feature is introduced in Rails 7. Using this gem, take the feature in advance for projects using Rails 6.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 6.0
 Project Readme

ActiveStorageVariant

Build Status Maintainability codecov Gem Version

The pre-defined variants is a very convenient feature. It's something like the styles option in Paperclip gem. Without it, it is a pain to use ActiveStorage as an alternative to Paperclip. Thanks to @fatkodima for the contribution.

The cool feature is introduced in Rails 7. By using this gem, you can take the feature in advance for projects using Rails 6. All configurations are the same, which means when you upgrade to Rails 7 in the future, you can remove this plugin without any effect.

Installation

gem "active_storage_variant"

Usage

class User < ActiveRecord::Base
  has_one_attached :avatar do |attachable|
    attachable.variant  :thumb, resize: "100x100"
    attachable.variant :medium, resize: "300x300", monochrome: true
  end
end

class Gallery < ActiveRecord::Base
  has_many_attached :photos do |attachable|
    attachable.variant  :thumb, resize: "100x100"
    attachable.variant :medium, resize: "300x300", monochrome: true
  end
end

<%= image_tag user.avatar.variant(:thumb) %>

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/yfxie/active_storage_variant.

License

MIT