Rails 4 image-path, image-url and asset-url no longer work in SCSS files

后端 未结 6 1004
醉梦人生
醉梦人生 2020-11-28 03:15

Are we supposed to use something else aside from image-url and others in Rails 4? They return different values that don\'t seem to make sense. If I have l

6条回答
  •  鱼传尺愫
    2020-11-28 03:58

    I just had this issue myself. 3 points that will hopefully help:

    • If you place images in your app/assets/images directory, then you should be able to call the image directly with no prefix in the path. ie. image_url('logo.png')
    • Depending on where you use the asset will depend on the method. If you are using it as a background-image: property, then your line of code should be background-image: image-url('logo.png'). This works for both less and sass stylesheets. If you are using it inline in the view, then you will need to use the built in image_tag helper in rails to output your image. Once again, no prefixing <%= image_tag 'logo.png' %>
    • Lastly, if you are precompiling your assets, run rake assets:precompile to generate your assets, or rake assets:precompile RAILS_ENV=production for production, otherwise, your production environment will not have the fingerprinted assets when loading the page.

    Also for those commands in point 3 you will need to prefix them with bundle exec if you are running bundler.

提交回复
热议问题