tarabyte
tarabyte

Reputation: 19222

How to Link to Images in CSS file in RoR 3.2 Project?

newb to RoR, but I'd prefer to NOT hard code my image path in application.css:

.nav {
  padding-top: 10px;
  height: 60px;
  background-image:url('/assets/static/bg-nav.png');
  background-repeat:repeat-x;
}

I'm also getting errors other places because of this. It took me to a couple tries to find that full path, but is there another tag I'm supposed to use? I previously had:

background-image:url('../images/static/bg-nav.png')

Which makes sense if you look at the directory tree, but somehow turns into something else. If I need to inline some rails here, does the file need to change to .css.erb?

Thank you.

Upvotes: 0

Views: 69

Answers (1)

tarabyte
tarabyte

Reputation: 19222

nevermind, i just started reading up more on the asset pipeline. here's an example of how to programmatically insert the appropriate path within your .css files (and no, do not need to be of other extension type):

.class { background-image: url(<%= asset_path '/mysubdirectory/myimage.png' %>) }

from: http://guides.rubyonrails.org/asset_pipeline.html

You begin the path from the app/assets/images/

Upvotes: 1

Related Questions