I generated a scaffold in ruby and I want to insert a background image to every page on the site but Im not sure what the link to the image should be.
my image is in app/assets/images/"dep.jpg"
this is what i have but it isnt working:
background-image:url('../images/dep.jpg'); }
Any help? thanks
We can background images in CSS using the background-image property. Then for the value, we can use the url() function where the image name or the image path is the parameter. The property has to be written after selecting the body tag in the CSS. This will enable the background image in the whole body of the webpage.
Use background-size property to cover the entire viewport The CSS background-size property can have the value of cover . The cover value tells the browser to automatically and proportionally scale the background image's width and height so that they are always equal to, or greater than, the viewport's width/height.
The most common & simple way to add background image is using the background image attribute inside the <body> tag. The background attribute which we specified in the <body> tag is not supported in HTML5. Using CSS properties, we can also add background image in a webpage.
In Rails 3.1, the path will actually be `/assets/dep.jpg':
background-image: url(/assets/dep.jpg);
If you convert your scaffold.css file to a Sass file (rename to scaffold.css.scss
) then you can use the helper:
background-image: image-url("dep.jpg");
The webserver in rails takes public
folder as the base of the application. Hence its looking for the specific image under /public/images/
instead of app/assets/images/"dep.jpg"
& since its not there over there you cannot get the image. Try to put your image in /public/images/
folder then it would work.
Edit: If you are using rails 3.1 then this would be different as Rails 3.1 uses the concept of asset pipeline for the assets of your application so then then path app/assets/images/dep.jpg
would obviously work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With