Use images in a css ruby on rails 4 error

I want to use images from a CSS, all my images are in the folder app/assets/imagenes and I add in the CSS like this:

#punica-page-header {
  background: url(../app/assets/imagenes/dimension.png) no-repeat center;
  background-size: cover; } 

than I add this in the application.html.erb:

<body class="punica-home-1">
    <header id="punica-page-header">
    </header>
</body>

this is the error that I have every time:

GET http://localhost:3000/app/assets/imagenes/dimension.png 404 (Not Found) jquery.self-660adc5….js?body=1:3734

I really appreciate if you can help me.

Upvotes: 0

Views: 70

Answers (3)

M. Karim
M. Karim

Reputation: 942

If you placed your image in app/assets/images folder, then can simply do it like this:

background: url(asset-path("dimension.png")) no-repeat center;

Just rename your css file extension like: filename.css.scss

It'll also work if you upload it in Heroku. Just make sure your Turbolink is working.

Upvotes: 1

RubyDigger19
RubyDigger19

Reputation: 835

You can use asset pipeline. Give extension to your stylesheet file my_file.scss.erb and then you can insert image like this

#punica-page-header {
background-image: url(<%= asset_path 'dimension.png' %>)
}

or

#punica-page-header {
background: url(<%= asset_data_uri 'dimesion.png' %>)
}

Edit: and of course images are in app/assets/images :)

Upvotes: 1

apparently I need to make it global in this way :

background: url("/assets/dimension.png")

Upvotes: 0

Related Questions