【问题标题】:rails include_blank and fontawesome iconsrails include_blank 和 fontawesome 图标
【发布时间】:2018-03-12 12:51:03
【问题描述】:

我可以使用一个很棒的字体图标作为包含空白项吗 Rails 选择标签?

(https://apidock.com/rails/ActionView/Helpers/FormTagHelper/select_tag)

我尝试了什么

<%= select_tag "near_within_distance",                                                                       
    options_for_select([                                                                                     
    ["Male", "50m "],                                                                                        
    ["Female", "f"],                                                                                         
    ], params[:near_within_distance]),                                                                       
    class: "form-control zcustom-select mr-sm-1",                                                            
    include_blank: "<i class='fa fa-search'></i>".html_safe %>    

导致

<select name="near_within_distance" id="near_within_distance" class="form-control zcustom-select mr-sm-1"><option value=""></option><option value="50m ">Male</option>
<option value="f">Female</option></select>

【问题讨论】:

  • 你看过这篇文章吗? stackoverflow.com/a/40662530/1625253
  • 有办法显示,但是我不认为你可以在include_blank中使用html还是我错了?
  • 40662530/1625253 很有趣。

标签: ruby-on-rails drop-down-menu font-awesome


【解决方案1】:

custom.css

@import url("http://fontawesome.io/assets/font-awesome/css/font-awesome.css");
select { font-family: 'FontAwesome', Verdana }

新的.erb

<%= select_tag "near_within_distance",                                                                       
    options_for_select([                                                                                     
    ["Male", "50m "],                                                                                        
    ["Female", "f"],                                                                                         
    ], params[:near_within_distance]),                                                                       
    class: "form-control zcustom-select mr-sm-1",                                                            
    include_blank: "&#xf042;".html_safe %>   

其中“”是字体真棒代码。您可以尝试字体真棒库中的任何人。

【讨论】:

    猜你喜欢
    • 2017-05-03
    • 1970-01-01
    • 1970-01-01
    • 2020-01-28
    • 2021-08-08
    • 2021-12-22
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    相关资源
    最近更新 更多