Where does CarrierWave stores uploads

225 views Asked by At

Please help me understand how does CarrierWave works. I'm using minimal Sinatra/DataMapper app with following contents:

class VideoUploader < CarrierWave::Uploader::Base
  storage :file
end

class Video
  include DataMapper::Resource
  property :id, Serial
  property :name, String
  property :desc, Text
  mount_uploader :file, VideoUploader
end

get '/' do
  slim :form
end

post '/' do
  video = Video.new
  video.name = params[:name]
  video.desc = params[:desc]
  video.file = params[:file]
  video.save
  redirect '/'
end

As I understood mount_uploader :file, VideoUploader string in Video definition adds .video method to Video instance, and I can store uploads assigning params[:file] to it. When I'm trying to send form from browser, the request successfully creates record in DB table, but I can't find any signs of file existence either in DB and public_directory. What I'm doing wrong?

1

There are 1 answers

0
prograils On

You probably should define the store_dir method inside the VideoUploader class:

class VideoUploader < CarrierWave::Uploader::Base

  storage :file

  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
....
end