开发者

Rails 3.1 Asset Pipeline and Caching

开发者 https://www.devze.com 2023-03-19 21:56 出处:网络
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.

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 th开发者_运维技巧is issues with referencing images in my assets folder inside my .scss files?


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.


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


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消