sass-rails asset pipeline: generating image paths incorrectly; `url(/images/blah.png)` instead of `url(/assets/blah.png)`

前端 未结 8 938
南笙
南笙 2021-01-01 17:31

In section 2.2.2, \"CSS and Sass\", I\'m told to put image-url(\'delete.png\') in my sass. And so I have.

However, it is generating CSS like

<         


        
相关标签:
8条回答
  • 2021-01-01 18:07

    Sanity check the file in your current asset pipepline. Check that it's in one of the directories listed in here:

    <%= debug Rails.application.config.assets.paths %>
    

    Next check at what relative path compass expects to find the image ( and see if it mat. According to the Compass config docs, one of these should tell you:

    <%= debug config.compass.http_images_path %>
    <%= debug config.compass.http_generated_images_path %>
    

    I'm guessing it's the first one. Either way, compare their path to your image's asset_path:

    <%= debug asset_path 'delete.png' %>
    

    If the paths don't match, maybe you need to adjust the path in your environment configs (development.rb, ...) to this for example:

    config.compass.http_images_path = '/assets.
    

    Alternatively, you could move the image to where http_images_path or the http_generated_images_path expect to find it.

    At the point, asset_path/asset_url (which are much less brittle than hardcoding) should hopefully work. I based this off of a similar technique I saw for stylesheets,

    0 讨论(0)
  • 2021-01-01 18:21

    After I edited my .scss file (added a space) and reload the page I got right result. After I removed the space it worked correctly.

    0 讨论(0)
提交回复
热议问题