自定义文件字段按钮 ruby​​ on rails [英] customize file_field button ruby on rails

查看:20
本文介绍了自定义文件字段按钮 ruby​​ on rails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试摆脱作为文件上传默认设置的丑陋按钮 rails.我想添加一个字形

 <%= f.file_field :image_url, class:"glyphicon glyphicon-camera" %>

这不起作用,我在此页面上看到的不同帖子中尝试了其他内容,但他们没有附加文件.

解决方案

您可以使用 css.

HTML:

<label for="文件输入"><span class="glyphicon glyphicon-camera"></span><%= f.file_field :image_url, id:"file-input" %>

CSS:

.image-upload >输入{显示:无;}.image-upload >标签{游标:指针;}

您可以在此处

找到工作示例

I'm trying to get rid of the ugly button rails has as default for the file upload. i want to add a glyphicon

  <%= f.file_field :image_url, class:"glyphicon glyphicon-camera" %>

This didn't work and I have tried other things in different post i saw on this page, but they don't attach the file.

解决方案

You can do it using css.

HTML:

<div class="image-upload">
   <label for="file-input">
     <span class="glyphicon glyphicon-camera"></span>
   </label>

   <%= f.file_field :image_url, id:"file-input" %>
</div>

CSS:

.image-upload > input
{
   display: none;
}
.image-upload > label{
  cursor:pointer;
}

You can find the working example here

这篇关于自定义文件字段按钮 ruby​​ on rails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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