0

In my rails app I'm trying to add tags to images uploaded to cloudinary cloud.

in my carrierwave, ImageUploader class

include Cloudinary::CarrierWave

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

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

...

I'm trying to add name of the record in tags, but it gives error

method 'model' is undefined for class ImageUploader.

how can I access value of the field name inside my uploader.

I'm new to rails.

please help, thanks in advance!

4

1 回答 1

3

您可以使用以下内容:

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 调用。

于 2013-06-10T20:07:43.803 回答