Sam D20
Sam D20

Reputation: 2575

Rails `image_path` not working in css file

I have the following line in my css file:

background-image: url(<%= image_path 'background.jpg' %>);

And it yields the following error:

Invalid CSS after "...und-image: url(": expected ")", was "<%= image_path ..."

I have also tried asset_path, but it has the same results.

Upvotes: 1

Views: 456

Answers (1)

Justin
Justin

Reputation: 4940

If you take a look at The asset pipeline, You can see that using image-url("background.jpg") becomes url(/assets/background.jpg), which is what you want if you image is in your /app/assets/images directory

So use

background-image: image-url("background.jpg")

Upvotes: 2

Related Questions