Heroku不提供背景图像,本地主机? [英] Heroku does not serve background image, localhost does?
问题描述
我的rails应用程序有问题(Rails 4.0.0.rc2,ruby 2.0.0p195)。
行为很奇怪:我的localhost显示背景
在heroku日志中,我可以看到以下错误:
ActionController :: RoutingError(No route matches [GET]/assets/piano.jpg):
我通过在custom.css.scss中插入以下代码创建了背景图片:
.full {
background:image-url(piano.jpg)无重复中心中心固定;
-webkit-background-size:cover;
-moz-background-size:cover;
-o-background-size:cover;
background-size:cover;
}
我用下面的代码触发这个,页面:
< body class =full>
....
< / body>
我已经在生产中运行了gem:
group:production do
pre>
gem'pg'
gem'rails_12factor'
end
在production.rb中,我将以下设置设置为true:
config.serve_static_assets = true
但是,图片未显示。
解决方案我自己找到了问题的解决方案:
RAILS_ENV = production bundle exec rake assets:precompile
在我的控制台中运行此命令后,图片显示正确。
以前,我只试图运行:
rake assets:precompile
不帮助。您必须在命令中解决生产环境。
我希望这可以作为其他用户的参考。
I have a problem with my rails application (Rails 4.0.0.rc2, ruby 2.0.0p195).
The behavior is weird: My localhost shows the background picture properly, Heroku doesn't.
In the heroku logs I can see the following error:
ActionController::RoutingError (No route matches [GET] "/assets/piano.jpg"):
I have created the background image by inserting the following code in my custom.css.scss:
.full { background: image-url("piano.jpg") no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; }
And I am triggering this with the following code, which I have on my static page:
<body class="full"> .... </body>
I already have the gem running in production:
group :production do gem 'pg' gem 'rails_12factor' end
In production.rb I have set the following setting to true:
config.serve_static_assets = true
However, the image is not being shown. Can you help me out?
解决方案I have found the solution for the issue myself:
RAILS_ENV=production bundle exec rake assets:precompile
After running this command in my console, the picture was shown properly.
Previously I had only tried to run:
rake assets:precompile
That alone didn't help. You have to address the production environment in your command.
I hope this serves as a reference for other users.
这篇关于Heroku不提供背景图像,本地主机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!