Search code examples
ruby-on-railsruby-on-rails-2

Image url in Css file under stylesheets under public Rails 2.3


I am working with Rails 2.3.5 and I have images in public/images/ which are added into css file named as custom.css

#cssmenu ul {
  background: url(nav-bg.png) repeat-x 0px 4px;
  height: 69px;
}

How can i make this read the image which in inside public/images ? I have tried this but it did not work

#cssmenu ul {
  background: url(<%= asset_path '/images/nav-bg.png' %>) repeat-x 0px 4px;
  height: 69px;
}

also this does not work

#cssmenu ul {
      background: url(<%= asset_path 'nav-bg.png' %>) repeat-x 0px 4px;
      height: 69px;
    }

Solution

  • Both examples are correct:

    #cssmenu ul {
      background: url(../images/nav-bg.png) repeat-x 0px 4px;
      height: 69px;
    }
    
    #cssmenu ul {
      background: url(/images/nav-bg.png) repeat-x 0px 4px;
      height: 69px;
    }