0

I need to insert a photo from my asset pipeline into my rails project. I am using a template from bootstrap (http://startbootstrap.com/template-overviews/clean-blog/)

The photo isn't showing up. Here is my code:

<!-- Set your background image for this header on the line below. -->
<header class="intro-header" style="background-image: image_url('home-bg.jpg')">

I looked here: Rails 4 image-path, image-url and asset-url no longer work in SCSS files and I tried every combination on the page, and it still doesn't work. When I do this:

  http://localhost:3000/assets/home-bg.jpg

then the photo does show in my browser. I have a feeling that it could be a problem from the css stylesheets I imported with the template, but I don't know any css at all so don't really know where to start in that way. Any ideas?

Community
  • 1
  • 1
jjjjjjjj
  • 4,203
  • 11
  • 53
  • 72

2 Answers2

2

Your ruby code is not being interpolated (interpreted). You must use "erb tags". Try this:

<header class="intro-header" style="background-image: <%= image_url('home-bg.jpg') %>">
Bryan Dimas
  • 1,389
  • 13
  • 18
0

You may need to try asset_path or asset_url.

<header class="intro-header" style="background-image: url(<%= asset_path 'home-bg.jpg' %>)">
vanburen
  • 21,502
  • 7
  • 28
  • 41