【问题标题】:how to serve thumbnail version of default image with carrierwave如何使用carrierwave提供默认图像的缩略图版本
【发布时间】:2016-12-19 05:35:19
【问题描述】:

我的默认图像正在使用carrierwave,但我无法获得默认图像的拇指版本。 @profile.photo@profile.photo.thumb 都返回相同的 default_profile.png。我如何让它工作

另外,当我上传照片时,@profile.photo.thumb 会正确返回上传照片的调整大小版本。

/assets/images

我有default_profile.pngthumb_default_profile.png,后者当然是前者的缩小版。我还尝试将拇指文件重命名为default_profile_thumb.png

profile_photo_uploader.rb 的相关部分:

 def default_url
   "default_profile.png"
 end

 version :thumb do
   process :resize_to_fill => [60, 60]
 end

【问题讨论】:

    标签: ruby-on-rails thumbnails carrierwave default-value


    【解决方案1】:
    def default_url
     "default_profile.png"
    end
    
    version :thumb do
      process :resize_to_fill => [60, 60]
      def default_url
        "thumb_default_profile.png"
      end
    end
    

    【讨论】:

      【解决方案2】:

      更好的方式:

        def default_url(*args)
          ActionController::Base.helpers.asset_path([version_name, "default_profile.png"].compact.join('_'))
        end
      

      【讨论】:

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