Rails:如何从 css 在 rails 中设置背景图像? [英] Rails: How to set a background image in rails from css?

查看:24
本文介绍了Rails:如何从 css 在 rails 中设置背景图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 rails 3.2,我必须为其中一个页面设置背景,我尝试了很多方法,但都没有成功,所以寻求一些好的帮助.我试过了

I am using rails 3.2 and i have to set a background for one of the page and i have tried many ways and nothing went right, so looking for some good help. I have tried

background: url(<%= asset_path 'background.jpg' %>)

background: url("public/background.jpg");

background-image:url('/assets/images/background.jpg')

没有任何效果.请帮帮我.

and nothing worked. Please help me.

推荐答案

在你的 CSS 中:

background-image: url(background.jpg);

background-image: url(/assets/background.jpg);

environments/production.rb 中:

# Disable Rails's static asset server (Apache or nginx will already do this)  
config.serve_static_assets = false

# Compress JavaScripts and CSS  
config.assets.compress = true

# Don't fallback to assets pipeline if a precompiled asset is missed  
config.assets.compile = false

# Generate digests for assets URLs  
config.assets.digest = true

这篇关于Rails:如何从 css 在 rails 中设置背景图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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