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

后端 未结 6 992
醉梦人生
醉梦人生 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:50

    Your first formulation, image_url('logo.png'), is correct. If the image is found, it will generate the path /assets/logo.png (plus a hash in production). However, if Rails cannot find the image that you named, it will fall back to /images/logo.png.

    The next question is: why isn't Rails finding your image? If you put it in app/assets/images/logo.png, then you should be able to access it by going to http://localhost:3000/assets/logo.png.

    If that works, but your CSS isn't updating, you may need to clear the cache. Delete tmp/cache/assets from your project directory and restart the server (webrick, etc.).

    If that fails, you can also try just using background-image: url(logo.png); That will cause your CSS to look for files with the same relative path (which in this case is /assets).

提交回复
热议问题