【问题标题】:How to correctly define asset paths in Rails 4如何在 Rails 4 中正确定义资产路径
【发布时间】:2014-07-04 13:06:35
【问题描述】:

请原谅我的菜鸟,我对 RoR 很陌生。

我在将图像部署到 Heroku 时无法加载它们。

我有两个从 css 文件加载的图像,我将其移至 scss。

一开始我有

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

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

在 layout.css 文件中

然后我注意到在本地一切正常,但是当我将它们部署到 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

【问题讨论】:

    标签: css ruby-on-rails heroku sass asset-pipeline


    【解决方案1】:

    在您的网站 CSS 中,一切看起来都很好。图像已正确加载。您正在使用文件

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

    要使其通过 image-url 工作,您应该在设置中正确设置:

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

    这些来自我在 Compass 的配置。您应该根据您的文件夹结构更改它们。

    【讨论】:

    • 当您说设置时,是否有我需要添加的配置文件?
    • 这些是 Compass 的配置(我将 Compass 与 SASS 一起使用)。但似乎在 SASS 中它的工作方式相同。看看stackoverflow.com/questions/9304607/…
    • 你说的是第一个答案吗?
    猜你喜欢
    • 2016-07-30
    • 1970-01-01
    • 1970-01-01
    • 2013-07-16
    • 1970-01-01
    • 2016-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多