【问题标题】:Add tags to images uploaded by carrierwave via cloudinary gem为carrierwave通过cloudinary gem上传的图片添加标签
【发布时间】:2013-06-04 13:12:51
【问题描述】:

在我的 rails 应用程序中,我正在尝试为上传到 cloudinary 云的图像添加标签。

在我的载波中,ImageUploader 类

include Cloudinary::CarrierWave

 # def cache_dir
 #   "#{Rails.root}/tmp/uploads"
 # end
 # 

process :convert => 'jpg'
cloudinary_transformation :quality => 80
process :tags => [ 'tag', model.name]

...

我正在尝试在标签中添加记录的名称,但它给出了错误

method 'model' is undefined for class ImageUploader.

如何在上传器中访问字段 name 的值。

我是 Rails 新手。

请帮忙,提前谢谢!

【问题讨论】:

    标签: image file-upload ruby-on-rails-3.2 carrierwave cloudinary


    【解决方案1】:

    您可以使用以下内容:

    class PictureUploader < CarrierWave::Uploader::Base  
      include Cloudinary::CarrierWave
    
      process :convert => 'jpg'
      cloudinary_transformation 
      :quality => 80
      process :assign_tags
    
      def assign_tags      
        return :tags => ['tag', model.name]      
      end
    end
    

    您可以定义任何返回参数散列的方法。然后,您可以使用“流程”调用应用自定义方法。参数被传递给上传 API 调用。

    【讨论】:

      猜你喜欢
      • 2014-11-24
      • 2014-08-10
      • 2016-12-22
      • 2016-06-28
      • 2019-03-27
      • 2016-09-20
      • 1970-01-01
      • 1970-01-01
      • 2016-04-12
      相关资源
      最近更新 更多