Additional fields in CarrierWave Uploader

carrierwave, ruby-on-rails

Solution

I'm not 100% clear what you are trying to do.

when I use carrierwave gem, I do create a path that holds some of that information. In my applaications I normally have a file app/uploaders/image_uploader.rb

  class ImageUploader < CarrierWave::Uploader::Base
    include CarrierWave::RMagick
    def store_dir
      # "uploads/image/file/187/"
      "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
    end
    ...
  end

from this I always know the model, what type of file, and the id. All other info about this model I normally save in the database.

I hope this helps and sets you in the right direction

Problem

I am trying to add additional fields to the CarrierWave Uploader so that they are stored as part of the Uploader itself and together with the CarrierWave fields, such as `@file`, `@model`, `@storage` etc. The fields are also version-specific, which is why I'd prefer to be able to access them via `<my_model>.<my_uploader>.attribute` and `<my_model>.<my_uploader>.versions[:<the_version>]` instead of additional columns in the model. I did try the carrierwave-meta gem, but ran into an error with it ( `NoMethodError: undefined method \'original_filename' for #<CarrierWave::Storage::Fog::File:0xab4134c>` ) that seems to not have been fixed yet. Any ideas or suggestions on how to best accomplish this?

Original source