2014-05-15 41 views
0

请原谅我的noobness,我是RoR的新手。如何在Rails 4中正确定义资产路径

我有麻烦我的图片时,我将它们部署到Heroku的加载。

我有从一个CSS文件,我移动到加载SCSS两个图像。

起初我在layout.css中文件

然后我发现一切正常本地有

background: url(../images/k-opacity-70.png); 

background: #111 url(../images/intro-bg.jpg) no-repeat center; 

,但是当我将它们部署到Heroku的图像不加载。

一些研究和尝试不同的多个后,我现在有

background: image-url('k-opacity-70.png'); 
background: #111 image-url('intro-bg.jpg') no-repeat center; 

在一个名为layout.css.scss

再次文件,图像正常工作在本地,而不是当我将我的应用程序部署到Heroku。

谁能告诉我我做错了什么?

我的应用程序是在blooming-coast-2140.herokuapp.com

----更新--- 我试着做在这里类似的帖子和其他网站没有运气看到的东西.. 。

gem ‘rails_12factor’, group: :production 

config.serve_static_assets = true 
config.action_dispatch.x_sendfile_header = ‘X-Accel-Redirect’ 
config.assets.compile = true 

heroku run rake assets:precompile 

rake assets:precompile RAILS_ENV=production 

回答

0

在您的网站CSS一切看起来不错。图像正确加载。您正在使用的文件

http://blooming-coast-2140.herokuapp.com/assets/k-opacity-70-26821b89b8efd61bf304cc109d3af47e.png and this file exists 

为了使通过图像的URL工作,你应该正确设置你的设置:

http_path = "../" 
images_dir = "img" 
relative_assets = true 

这些都是从我的指南针配置。您应该根据您的文件夹结构更改它们。

+0

当你说设置有一个配置文件,我需要添加到? –

+0

这些是来自Compass的配置(我将Compass和SASS一起使用)。但在SASS中它似乎以同样的方式工作。只要看看http://stackoverflow.com/questions/9304607/sass-rails-helpers-image-url-asset-url-are-not-working-in-rails-3-2-1 –

+0

你在说的是第一个答案? –

相关问题