0

I have model1 and model2. I need to upload the images of the two models in two different directories. For now my image_uploader is:

class ImageUploader < CarrierWave::Uploader::Base

  include CarrierWave::RMagick

  storage :file

  def store_dir
    "uploads/images"
  end
end

The images of model2 should be stored in uploads/images2. How can I define this?

user929062
  • 807
  • 4
  • 12
  • 33

2 Answers2

0

Sorry, the question was not very intelligent. The answer seems to be creating a second uploader with

rails g uploader model2

user929062
  • 807
  • 4
  • 12
  • 33
0

If the only thing different between your uploaders is the store_dir function, then you don't need to create another uploader (although you can). Inside your uploader, you have access to the model, so you could do something like:

def store_dir
    if model.class==Model1
        "upload/images1"
    elsif model.class==Model2
        "upload/images2"
    else
        "upload/images"
    end
end
cgat
  • 3,689
  • 4
  • 24
  • 38