供应商/资产/图像不在轨道上渲染图像4

时间:2015-08-25 16:04:27

标签: ruby-on-rails ruby-on-rails-4 asset-pipeline ruby-on-rails-4.2

我启动了一个新的应用程序,并在供应商/资产文件夹中添加了一个主题。

我在vendor / assets中创建了一个名为images的文件夹,并将以下代码段添加到我的应用程序代码中:

# inside config/initializers/assets.rb.
Rails.application.config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)

之后,我去了控制台并检查了我的资产路径

>> Rails.application.config.assets.paths
=> ["/home/renatojf/Documents/Code/bhiz/app/assets/images", "/home/renatojf/Documents/Code/bhiz/app/assets/javascripts", "/home/renatojf/Documents/Code/bhiz/app/assets/stylesheets", "/home/renatojf/Documents/Code/bhiz/vendor/assets/fonts", "/home/renatojf/Documents/Code/bhiz/vendor/assets/images", "/home/renatojf/Documents/Code/bhiz/vendor/assets/javascripts", "/home/renatojf/Documents/Code/bhiz/vendor/assets/stylesheets", "/home/renatojf/.rvm/gems/ruby-2.2.2@bhiz/gems/twitter-bootstrap-rails-3.2.0/app/assets/fonts", "/home/renatojf/.rvm/gems/ruby-2.2.2@bhiz/gems/twitter-bootstrap-rails-3.2.0/app/assets/images", "/home/renatojf/.rvm/gems/ruby-2.2.2@bhiz/gems/twitter-bootstrap-rails-3.2.0/app/assets/javascripts", "/home/renatojf/.rvm/gems/ruby-2.2.2@bhiz/gems/twitter-bootstrap-rails-3.2.0/app/assets/stylesheets", "/home/renatojf/.rvm/gems/ruby-2.2.2@bhiz/gems/twitter-bootstrap-rails-3.2.0/vendor/assets/stylesheets", "/home/renatojf/.rvm/gems/ruby-2.2.2@bhiz/gems/turbolinks-2.5.3/lib/assets/javascripts", "/home/renatojf/.rvm/gems/ruby-2.2.2@bhiz/gems/jquery-rails-4.0.4/vendor/assets/javascripts", "/home/renatojf/.rvm/gems/ruby-2.2.2@bhiz/gems/coffee-rails-4.1.0/lib/assets/javascripts"]

如您所见,路径正在加载供应商/资产/图像。 问题是主题中的所有css文件都调用图像:

.header-full-title {
  background-image: url("../img/colors/blue/logo_big.png");
}

当我尝试加载页面时,在开发过程中,我得到了No route matches [GET] "/img/colors/blue/logo_big.png")

那么我该如何解决这个问题呢?

1 个答案:

答案 0 :(得分:0)

是的..在某个地方我发现,如果rails使用资产管道提供静态图像,您可以直接调用它而不在资产路径中使用/img

所以..这有效:

background-image: url("colors/blue/logo_big.png");

如果你在它上面再添加一个文件夹..就像:

- vendor
--assets
----images
------img
--------colors