我有一个csv文件要导入到heroku中的数据库,而csv包含图像名称,我必须将图像放在一个文件夹中,并在导入代码中指定其路径。所以我尝试将图像保存在公共文件夹和资源文件夹中,并返回错误,如下所示
Errno::ENOENT (No such file or directory - /images/picture17.jpg):
我甚至在production.rb中设置了如下
config.serve_static_assets = true
但我仍然得到错误。请帮帮我。
编辑:
csv_text = File.read('sample.csv')
csv = CSV.parse(csv_text, :headers => true)
csv.each do |row|
Model.create!({"name"=>row['name'], "age"=>row['age'], "pic"=>File.open("/images" + row['pic_name'])})
end
答案 0 :(得分:0)
在免费计划上,Heroku会以特定间隔删除您的公共/资产目录
(我想一天一次。)因此,您应该通过自3.1 +以来已集成在Rails中的资产管道来提供资产
虽然您提到您正在导入CSV文件,但我猜测实际上已为此应用程序设置了数据库。
让我向您介绍CarrierWave结合Cloudinary的甜蜜生活。
花点时间阅读CarrierWave文档:https://github.com/jnicklas/carrierwave
Cloudinary文档:http://cloudinary.com/documentation
这是好的部分: Heroku实际上与cloudinary相当整齐https://addons.heroku.com/cloudinary
整合只需在您的上传器中包含Cloudinary :: CarrierWave标头,这应该可以解决问题!