简体   繁体   English

Ruby on Rails:数据库中的背景CSS图像

[英]Ruby on Rails : Background CSS Image from Database

I want to create a picture management through my ActiveAdmin administration panel. 我想通过ActiveAdmin管理面板创建图片管理。

I use Carrierwave to upload images from my administration panel, however I fail to display these images as background-image within my CSS code... :/ 我使用Carrierwave从管理面板上传图像,但是无法在CSS代码中将这些图像显示为背景图像...:/

...because of the following error: ...由于以下错误:

couldn't find file '<%= Image.find(1).path %>'

错误截图

Here is my CSS: 这是我的CSS:

header{
   background-image: asset-data-url("<%= Image.find(1).path %>");
}

My HTML: 我的HTML:

<header>
<div class="header-content">
    <div class="header-content-inner">
        <h1>Your Favorite Source of Free Bootstrap Themes</h1>
        <hr>
        <p>Start Bootstrap can help you build better websites using the Bootstrap CSS framework! Just download your template and start going, no strings attached!</p>
        <a href="#about" class="btn btn-primary btn-xl page-scroll">Find Out More</a>
    </div>
</div>

And the image administration view: 和图像管理视图:

查看截图

I don't understand how do I link my image to the background-image CSS property? 我不明白如何将图片链接到background-image CSS属性?

Calling Rails Database queries in CSS stylesheet will not work. 在CSS样式表中调用Rails数据库查询将不起作用。 Instead you can rework on the HTML code like the below, 相反,您可以像下面这样处理HTML代码,

<header style="background-image: url(<%= Image.find(1).path %>);">

and remove the background image code in the CSS. 并删除CSS中的背景图片代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM