使用ActiveStorage更改Spree默认映像大小3.6

时间:2018-10-30 20:18:31

标签: ruby-on-rails spree rails-activestorage

我将Spree 3.6与Rails 5.2一起使用。 Spree为使用PaperClip的旧系统提供了文档,但是对于使用Active Storage的新系统则没有抽取。 任何人都有经验吗?

谢谢

1 个答案:

答案 0 :(得分:0)

要更改默认图像尺寸或添加新尺寸,您需要创建装饰器文件app/models/spree/image_decorator.rb

module YourApplication
  module Spree
    module ImageDecorator
      module ClassMethods
        def styles
          {
            mini:    '48x48>',
            small:   '100x100>',
            product: '240x240>',
            large:   '600x600>',
          }
        end
      end

      def self.prepended(base)
        base.singleton_class.prepend ClassMethods
      end
    end
  end
end

Spree::Image.prepend ::YourApplication::Spree::ImageDecorator

https://guides.spreecommerce.org/developer/images.html