Ruby on Rails 5.2-具有活动存储的背景图像 [英] Ruby on rails 5.2 - background image with active storage
本文介绍了Ruby on Rails 5.2-具有活动存储的背景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已将应用程序升级到Rails 5.2,并且正在使用rails的活动存储.
I upgraded my app to rails 5.2 and I am using the active storage of rails.
如果我想使用上传的图片作为背景,哪种方法最好?我想将调整后的图片300x300用于背景.
In case I want to use the picture I uploaded as a background, which method is the best? I would like to use a resized picture 300x300 for the background.
<div style="background: ... ">
推荐答案
<div class="index-img">
<div class="bg-img" style="background-image: url(<%= rails_blob_url(@user.avatar) %>)"></div>
</div>
然后可以在css中对其进行样式设置
then can style it in css like
.index-img{
position: relative;
width: 100%;
height: 250px;
background: $grey;
}
.bg-img{
width: 100%;
height: 100%;
@include background-image();
}
这篇关于Ruby on Rails 5.2-具有活动存储的背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文