asset_path in scss file rails

我的梦境 提交于 2019-11-29 09:15:25

This doesn't look correct:

.right-bar-filler{
    background:url(asset_path('right_bar_filler.jpg', image)) repeat-y;
    padding-top:0px;
}

If you want to use the asset_path helper, it needs to run inside the erb tags (<% %>)

.right-bar-filler{
    background:url(<%= asset_path('right_bar_filler.jpg', image) %>) repeat-y;
    padding-top:0px;
}

and make sure you name the file correctly, i.e. example_filename.css.erb


UPDATE: Sorry, I didn't notice you were using SASS, not CSS. My above answer is not what you need.

Try this instead:

.right-bar-filler{
    background:url(asset-path('right_bar_filler.jpg', image)) repeat-y;
    padding-top:0px;
}

I.e. I think the asset path helper uses hyphens in SASS, not underscores

http://rubydoc.info/github/petebrowne/sprockets-sass/master/Sprockets/Sass/Functions

Did you rake assets:precompile? By default, Rails will not compile assets in production. The recommended workflow is to compile assets as part of your deployment.

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