Reputation: 217
I'm working on a rails project where I need to use an image as a background on a div, but I can't seem to figure out why the full url isn't being generated. It only generates the path /blog/imageurl.png. This project uses slim, which isn't something i'm new to.
My Code
.blog-post style="background-image: url (#{post.image})"
Code that works on the same page to generate the image
= image_tag "#{post.image}"
What have I missed to get this working as a background image?
Upvotes: 1
Views: 239
Reputation: 748
Try this
.blog-post style="background-image: url(#{image_url(post.image)})";
Upvotes: 1
Reputation: 16507
Since it is the string at first be sure that server serves path to images, so enter to broser path like:
and make sure that the image is shewn. Next add lack part of path to the string, and add missing ;
char at the at of line:
.blog-post style="background-image: url (#{ActionController::Base.helpers.asset_path("images/" + post.image)});"
Upvotes: 0
Reputation: 6749
Try this:
.blog-post{style: "background-image: url(#{image_path post.image})"}
Upvotes: 1