0

I'm trying to set a background image on 1 of the pages in my Rails 3 app, but it's not showing.

What am I doing wrong?? Here is the relevant code:

<div class="hero-unit" style="background: url('public/assets/fks.JPG') ;">

Thanks,

Faisal

mu is too short
  • 413,090
  • 67
  • 810
  • 771
hikmatyar
  • 507
  • 1
  • 9
  • 33

1 Answers1

5

Try this:

<div class="hero-unit" style="background: url('assets/fks.JPG') ;>

Better still:

<div class="hero-unit" style="background-image: url(<%= asset_path 'fks.JPG' %>) ;>
Victor
  • 12,632
  • 18
  • 77
  • 142
  • 1
    You should use the 2nd method because the first method is in relative URL. – Victor Apr 27 '12 at 03:22
  • will do. weird that the code seems to work fine even with the missing double quote.. – hikmatyar Apr 27 '12 at 03:26
  • 1
    @hikmatyar: That's just the browser being forgiving and (correctly) fixing your HTML behind your back, don't depend on it though. – mu is too short Apr 27 '12 at 03:27
  • @hikmatyar, like what "mu is too short" said, quotes are quite optional. http://stackoverflow.com/questions/851724/css-background-image-what-is-the-correct-usage Your problem is not the quote, but the path of the assets. – Victor Apr 27 '12 at 03:29