0

Can I use a font awesome icon as the include blank item of a rails select tag?

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

What I tried

<%= 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 %>    

Resulted in

<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>
american-ninja-warrior
  • 7,397
  • 11
  • 46
  • 80

1 Answers1

0

custom.css

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

new.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 %>   

Where "&#xf042" is the font awesome code. You can try anyone from font awesome library.

sam
  • 372
  • 2
  • 12