【问题标题】:override paperclip has_attached_file settings that were set in a gem覆盖在 gem 中设置的回形针 has_attached_file 设置
【发布时间】:2019-05-28 22:29:52
【问题描述】:

在我的项目中,我有一个使用回形针作为文件附件的 gem。 gem 中的示例模型:

class Example do
...
    has_attached_file :image,
      styles: { mini: '32x32>', normal: '128x128>' },
      default_style: :mini,
      url: '/example/url/:id/:style/:basename.:extension',
      path: ':rails_root/public/example/url/:id/:style/:basename.:extension',
...
end

我想修改图像,而不是 mininormal 尺寸,我可以添加另一个尺寸。我也想改变路径。我该怎么做?我尝试创建一个装饰器,例如:

Example.class_eval do
    has_attached_file :image,
      styles: { mini: '32x32>', normal: '128x128>', large: '1024x1024' },
      default_style: :mini,
      url: '/example/url/:id/:style/:basename.:extension',
      path: 'updated/example/url/:id/:style/:basename.:extension',
end

这没有做任何事情。

【问题讨论】:

    标签: ruby-on-rails-5 paperclip


    【解决方案1】:

    不确定你现在是否已经解决了这个问题,但是对于这个问题的任何未来观众......

    您可以通过修改类的attachment_definitions 属性来做到这一点。例如,您可以添加一个初始化器:

    Example.attachment_definitions[:image][:styles][:normal] = "1000x500"
    Example.attachment_definitions[:image][:path] = '...'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多