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

前端 未结 8 935
南笙
南笙 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 17:58

    This looks to be due to your version of sass-rails (3.1.0). I can reproduce your problem (thanks for posting the Gemfile) and it goes away when bumping to sass-rails 3.1.4.

    Try upgrading to 3.1.4 and clearing tmp/cache. Also make sure you're not hitting any browser caches.

    I know you said 3.1.4 was causing other problems... have you tried higher versions?

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

    This is our combo of haml-rails, compass and sass-rails. We're running rails 3.2.6 though. This has worked well for us.

    gem 'compass', git: 'git://github.com/chriseppstein/compass.git', ref: '3a4c5c75dca9f07f6edf2f0898a4626269e0ed62'

    gem 'haml-rails', git: 'git://github.com/indirect/haml-rails.git', ref: '92c41db61f20a9f122de25bc73e5045cfccdbcd5'

    gem 'sass-rails', '~> 3.2.5'

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

    If you do not have this already, name your css file *.css.scss (as opposed to .sass - if you do this, you might need to adjust the syntax of some statements). Then use the image_path helper instead of image-path, e.g.:

    background-image:url(image_path('delete.png'));
    

    I expect this to solve your issue. If it does not, what is the asset path generated by this approach for you?

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

    For me,

    Changing image_path to image-path worked for .scss. Later on, I changed to image_path again and it's working fine now.

    Deleting cache didnt help me.

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

    Not necessarily a solution, but certainly an available option: If you're open to using compass spriting, you'll cut down on the number of http requests and be able to manually specify your image path with a sprite map, ie '$sprites: sprite-map("PATH/*.png");'

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

    It really looks like this issue: https://github.com/rails/sass-rails/issues/57 If so you should try to find the good combination of versions between Compass and Sass-rails.

    And maybe upgrade everything (Rails included) to latest versions, it's still the best way to do (use bundle outdated command in bundler 1.2 to know what Gems to upgrade)

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