asset_path in scss file rails

后端 未结 2 952
日久生厌
日久生厌 2020-12-18 19:34

I am having issues with asset_path in production. Rails 3.1.1

#config/environments/development.rb
Scc::Application.configure do
  # Settings specified here w         


        
相关标签:
2条回答
  • 2020-12-18 19:55

    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.

    0 讨论(0)
  • 2020-12-18 20:17

    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

    0 讨论(0)
提交回复
热议问题