Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store files out side the public folder in carrierwave?

Carrierwave by default takes in the url generated by store_dir in the uploader and prepends the path to the public folder of the rails application and stores the files.

For example if

def store_dir
  "uploads/#{model.id}"
end

then the file is stored at public/uploads/:attachment_id

If one tries to move the stored files out of the public folder still it saves in the public folder. Does anyone have an idea of how to store the files outside the public folder??

like image 539
Avinasha Shastry Avatar asked May 12 '11 13:05

Avinasha Shastry


2 Answers

the cleanest way to do this, is by setting the CarrierWave root option

CarrierWave.configure do |config|
  config.root = Rails.root
end

then store_dir will be used inside this root.

like image 66
Elmatou Avatar answered Nov 04 '22 20:11

Elmatou


I realize this isn't really a current question, but I stumbled on it looking for something else. The answer is simply to use Rails.root, eg:

  def store_dir
    "#{Rails.root}/private/files/#{model.id}"
  end
like image 13
Preacher Avatar answered Nov 04 '22 21:11

Preacher