如果我在 Heroku 上的应用程序中加载文件,一切正常,但是当我再次尝试重新加载应用程序时,它给了我以下错误:
2013-01-25T08:48:31+00:00 app[web.1]: app/controllers/main_controller.rb:20:in `index'
2013-01-25T08:48:31+00:00 app[web.1]:
2013-01-25T08:48:31+00:00 app[web.1]:
2013-01-25T08:48:31+00:00 app[web.1]: Errno::ENOENT (No such file or directory - /app/config/cases/casesID6.yml):
2013-01-25T08:48:31+00:00 app[web.1]: app/controllers/main_controller.rb:20:in `read'
本地它工作正常!
主控制器:
# importo yaml di configurazione
require 'yaml'
if Survey.exists?(1)
@idOfSurvey = Survey.find {|s| s['active_state'] == true}['id']
nameOfSurvey = "casesID"+String(@idOfSurvey)+".yml"
@survey = YAML::load(ERB.new(IO.read(File.join(Rails.root, 'config/cases', nameOfSurvey))).result)
else
render :action => 'noYaml' and return
end
上传控制器:
#inserisco il nuovo questionario
survey = Survey.new
if Survey.exists?(1)
n = String(Integer(Survey.maximum("Id"))+1)
survey.name = "casesID#{n}"
else
survey.name = "casesID1"
end
File.open(Rails.root.join('config/cases', survey.name+".yml"), 'wb+') do |file|
file.write(uploaded_io.read)
end
survey.save()
我相信我上传到 Heroku 的文件可能会被平台清除,例如内存问题,或者因为它将它们保存为临时文件,这可能吗?解决方案!
我再说一遍,在本地一切正常:(