Rails 3.1 Asset Pipeline and Caching

时光怂恿深爱的人放手 提交于 2020-01-03 16:56:34

问题


I'm working with Rails 3.1's asset pipeline and although it seems to work flawlessly in my development environment on my localhost, I'm having huge issues with it on engine yard.

Here's my basic problem.

When I include images for a background in one of my scss files:

      a {
        color: #3c7f8b;
        font-weight: bold;
        padding-left: 35px;
        font-size: 13px;
        display: block;
        background: white url(shade.png) top right;
        &:hover {
          color: #222222;
          background: white url(shade2.png) top right; }
        &.on {
          color: #222222;
          background: white url(shade2.png) top right; } } }

I run into the following issues: Even though I have precompiled my assets, the browser requests /assets/shade.png instead of /assets/shade-FINGERPRINT.png which is the actual file that exists.

Does anybody know what I can fix this issues with referencing images in my assets folder inside my .scss files?


回答1:


Check out the answer from 'tybro0103' on this post - Rails 3.1 and Image Assets

basically change the file from scss to scss.erb and then use the asset_path helper method

pre-compile before deploy

disclaimer: i have not tried this myself




回答2:


You should use image-url rather than url to reference images when using scss in Rails 3.1.

Also, ensure you load compass before sass-rails, as sass-rails over-rides the asset methods to work with the asset pipeline.

Lastly, if you're using capistrano to deploy, add in

load 'deploy/assets'

To enable asset compilation when you deploy.




回答3:


qnm Actually I think there is an error with the image_url helper. Not sure if they fixed it but I saw a recommendation to use asset_url with the "image" explicting stated.

i.e. asset_url("some.img","image)



来源:https://stackoverflow.com/questions/6683584/rails-3-1-asset-pipeline-and-caching

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!