简体   繁体   English

rails 4:Errno :: ENOENT(没有这样的文件或目录@ rb_sysopen - / assets /

[英]rails 4: Errno::ENOENT (No such file or directory @ rb_sysopen - /assets/

I've just deployed my app to heroku and I'm having a lot of trouble trying to read some assets. 我刚刚将我的应用程序部署到heroku,我在尝试阅读一些资产时遇到了很多麻烦。

I am trying to dynamically load some css from multiple files, then recompile them with some changes later. 我试图从多个文件动态加载一些CSS,然后重新编译它们稍后进行一些更改。 The line that keeps breaking is the first file load: 不断破坏的行是第一个文件加载:

@css_asset_bootstrap = File.open(ActionController::Base.helpers.asset_path('bootstrap.css'), "r").read

which generates this error: 这会产生此错误:

2015-04-07T23:30:50.098831+00:00 app[web.1]: Errno::ENOENT (No such file or directory @ rb_sysopen - /assets/bootstrap-2d25733981c30e34bd9aa0fb75388f08.css):

I've tried a lot of things, including moving all my assets to aws cloudfront. 我已经尝试了很多东西,包括将我的所有资产都移到了aws cloudfront。 Is there a way to get around this? 有办法解决这个问题吗? Works perfectly in development environment. 在开发环境中完美运行。

Just to confirm a few things. 只是为了确认一些事情。 I've successfully precompiled and uploaded the file. 我已成功预编译并上传了该文件。 The file definately exists as I can see it in 该文件肯定存在,因为我可以看到它

heroku run bash
cd /public/assets/

I can also see it when I moved the assets to cloudfront. 当我将资产迁移到云端时,我也可以看到它。

Thanks. 谢谢。

edit 1: Not sure if this is important information, but with the file on cloudfront, I can run heroku run bash to start a shell session on heroku. 编辑1:不确定这是否是重要信息,但是使用cloudfront上的文件,我可以运行heroku run bash在heroku上启动shell会话。 Then I can: 然后我可以:

curl http://xxx.cloudfront.net/assets/bootstrap-2d25733981c30e34bd9aa0fb75388f08.css

And get the file ok. 并获得文件确定。 I was thinking maybe it was a permissions error but everything is set to public and it all seems to work from heroku to the aws server. 我想也许这是一个权限错误,但一切都设置为公共,它似乎从heroku到aws服务器。

You're asking for the file from a relative path, which might not always work. 您要求相对路径中的文件,这可能并不总是有效。 Try absolute: 尝试绝对:

@css_asset_bootstrap = File.open(Rails.root + ActionController::Base.helpers.asset_path('bootstrap.css'), "r").read

Another possibly bigger problem is that Heroku has an ephemeral filesystem, and so any changes you write to it can be obliterated at any time when the dyno is culled. 另一个可能更大的问题是Heroku有一个短暂的文件系统,所以你写的任何更改都可以在dyno被剔除的任何时候消除。

In my case, using a virtual machine Rails.root give me this: '/home/vagrant/projects/.../my-nice-app' what is totally uncool. 在我的情况下,使用虚拟机Rails.root给我这个: '/home/vagrant/projects/.../my-nice-app'什么是完全不酷的。

I use instead request.url with give me: 'http://localhost:3000/ ' what it is exactly what I want. 我使用request.url来给我: 'http://localhost:3000/ '这正是我想要的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Errno :: ENOENT - 没有这样的文件或目录@ rb_sysopen - Errno::ENOENT - No such file or directory @ rb_sysopen Errno::ENOENT 没有那个文件或目录@rb_sysopen - Errno::ENOENT No such file or directory @ rb_sysopen 如何修复“Errno::ENOENT: No such file or directory @ rb_sysopen”? - How to fix “Errno::ENOENT: No such file or directory @ rb_sysopen”? Errno :: ENOENT(无此类文件或目录@ rb_sysopen-aws.yml) - Errno::ENOENT (No such file or directory @ rb_sysopen - aws.yml) Errno::ENOENT: 没有这样的文件或目录@rb_sysopen - /tmp/ - Errno::ENOENT: No such file or directory @ rb_sysopen - /tmp/ Rails的公共目录中的文件-Errno :: ENOENT(无此类文件或目录@ rb_sysopen - Files in public directory in Rails - Errno::ENOENT (No such file or directory @ rb_sysopen 带有 Rails API 的 Expo Image Picker 获取 Errno::ENOENT(没有这样的文件或目录 @ rb_sysopen - Expo Image Picker With Rails API gets Errno::ENOENT (No such file or directory @ rb_sysopen Errno::ENOENT: No such file or directory @ rb_sysopen webpacker:compile Issues for Rails depoloyment - Errno::ENOENT: No such file or directory @ rb_sysopen webpacker:compile Issues for Rails depoloyment 带有回形针的Errno :: ENOENT(无此类文件或目录@ rb_sysopen-aws.yml) - Errno::ENOENT (No such file or directory @ rb_sysopen - aws.yml) in rails with paperclip 看到“Getting Errno::ENOENT 'no such file or directory @ rb_sysopen'”时如何在 Rails 中获取正确的 Tempfile 文件路径 - How to get a proper filepath of Tempfile in Rails when seeing "Getting Errno::ENOENT ' no such file or directory @ rb_sysopen'"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM