在我的代码中,我有以下 block
Tempfile.open([model.id.to_s, '.txt'], Rails.root.join('tmp')) do |file|
begin
file << somedata_i_have_before
model.file = file # using paperclip gem attached file
ensure
# close and delete file
file.close
file.unlink
end
end
这段代码在本地和生产中运行良好...问题是我已经设置了 Wercker应用程序自动测试和部署,但上述 block 在 wercker 上失败并返回以下错误
Errno::ENOENT:
No such file or directory @ rb_sysopen - /pipeline/build/tmp/539e01d4776572049647010020140615-1174-ajp5tf.txt
# ./lib/some_lib.rb:63:in `some_method'
有什么想法可以解决这个问题,以便 wercker 上的构建通过吗?
最佳答案
我猜 tmp 文件夹在您的存储库中被忽略(.gitignore),因此当您执行干净的存储库克隆时不会创建它。
我可能是错的,但是 Tempfile.open([model.id.to_s, '.txt'], Rails.root.join('tmp'))
不会创建 tmp 文件夹,它期望它已经存在。
我在忽略文件夹方面遇到了类似的问题 - 您可以使用干净的 git 克隆对其进行测试,然后执行此测试,就像它在 CI/CD 服务器上运行一样。
关于ruby-on-rails - Wercker 测试无法打开临时文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24233962/