【问题标题】:where to keep images in heroku for using it in csv in rails app?在哪里将图像保存在heroku中以便在rails应用程序的csv中使用它?
【发布时间】:2013-02-20 10:32:12
【问题描述】:

我有一个 csv 文件要导入到 heroku 中的数据库,并且 csv 包含图像名称,我必须将图像放在一个文件夹中并在导入代码中指定其路径。所以我尝试将图像保存在公用文件夹和资产文件夹中,它返回错误如下

Errno::ENOENT (No such file or directory - /images/picture17.jpg):

我什至在 production.rb 中设置了 true 如下

 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

【问题讨论】:

  • 您需要向我们提供更多详细信息 - 粘贴导入代码。
  • 我已经在编辑中发布了导入代码

标签: ruby-on-rails ruby-on-rails-3 heroku paperclip


【解决方案1】:

在免费计划中,Heroku 会每隔一段时间删除你的 public/assets 目录

(我想每天一次。)因此,您应该通过自 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 标头即可!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-27
    • 2016-08-25
    • 1970-01-01
    • 2016-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多