在Ruby中的Ruby on Rails 2中添加背景图片 [英] Adding a background image in Ruby on Rails 2 in CSS

查看:701
本文介绍了在Ruby中的Ruby on Rails 2中添加背景图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ruby中生成了一个脚手架,我想在网站的每个页面上插入一个背景图片,但我不知道图片的链接应该是什么。

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.

我的图片位于 app / assets / images /dep.jpg

这是我的,但它不工作:

this is what i have but it isnt working:

background-image:url('../images/dep.jpg');
}

任何帮助?感谢

推荐答案

rails中的网络服务器以 public 应用程序。因此,它寻找 / public / images / 而不是 app / assets / images /dep.jpg&因为它不在那里,你不能得到的形象。尝试将您的图像放在 / public / images / 文件夹中,然后它会工作。

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.

如果你使用rails 3.1,那么这将是不同的,因为Rails 3.1使用资源管道的概念为你的应用程序的资产,然后路径 app / assets / images / dep.jpg 显然会工作。

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.

这篇关于在Ruby中的Ruby on Rails 2中添加背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆