【发布时间】:2015-07-30 02:31:10
【问题描述】:
我通读了 Stack Overflow 和 Google 上的每个链接。我花了很多时间尝试一些东西。但无法解决这个问题。
我的应用资产中有以下文件夹结构
app
->images
->application (folder)
image1..
image2..
->icons (folder)
image3..
image4..
我的样式表文件夹中有 application.css 文件,如下所示:
app
->stylesheets (folder)
application.css
->application (folder)
app.css
application.css 有以下条目:
*= require_tree ./application
因此它正在加载我的 app.css 文件,该文件包含我的应用程序的所有 css。在我的 app.css 中,我正在使用:
{background: url('icons/user-business-gray.png') no-repeat 2px center transparent;}
我的 config/environments/production.rb 有:
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
#config.serve_static_assets = false
config.assets.compile = false
config.assets.digest = true
我的 config/initializers/assets.rb 有:
Rails.application.config.assets.paths << Rails.root.join( "app/assets/images/application")
我做到了:
RAILS_ENV=production rake assets:precompile
我可以正确地看到我在 public/assets、public/assets/application 和 public/assets/icons 中散列的所有图像。
在开发模式下一切正常。但我在生产模式下看不到 app.css 文件中引用的任何图像。
如果我直接使用<%= image_tag('icons/user-business-gray.png') %> 将图像添加到 .erb,我可以正确看到图像。但是我看不到上面引用的 app.css 中引用的任何图像。
我什至将 app.css 的名称更改为 app.css.scss 并引用了如下图像:
{background: url(assets-path('icons/user-business-gray.png')) no-repeat 2px center transparent;}
但仍然是同样的问题。非常感谢任何帮助。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 sass