如何在载波中将文件存储在公用文件夹之外? [英] How to store files out side the public folder in carrierwave?
问题描述
默认情况下,Carrierwave会在上载器中使用 store_dir
生成的URL,并在rails应用程序的公用文件夹中添加路径并存储文件。
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.
例如,如果
def store_dir
"uploads/#{model.id}"
end
然后将文件存储在 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??
推荐答案
最干净的方法是通过设置CarrierWave根选项
the cleanest way to do this, is by setting the CarrierWave root option
CarrierWave.configure do |config|
config.root = Rails.root
end
然后 store_dir
将在此根目录内使用。
then store_dir
will be used inside this root.
这篇关于如何在载波中将文件存储在公用文件夹之外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!