How do I implement bootstrap dropdown in rails with categories -
i'm wanting implement bootstrap's dropdowns in rails project similar code below provided on bootstrap's website:
<div class="dropdown"> <button class="btn btn-default dropdown-toggle" type="button" id="dropdownmenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> dropdown <span class="caret"></span> </button> <ul class="dropdown-menu" aria-labelledby="dropdownmenu1"> <li><a href="#">action</a></li> <li><a href="#">another action</a></li> <li><a href="#">something else here</a></li> <li role="separator" class="divider"></li> <li><a href="#">separated link</a></li> </ul> </div>
i have section in project can add new/edit categories use in main form. code have unformatted select/dropdown is:
<%= f.select :category_id, category.all.map { |category| [ category.name, category.id ] }, class: "form-control" %>
which doesn't seem apply bootstrap formatting, i've tried changing code around bit be:
<%= f.select :category_id, options_for_select([category.all.map { |category| [ category.name, category.id ] }]), {}, class: "form-control" %>
this gives dropdown box bootstrap style box, dropdowns under default selection don't have formatting similar bootstrap's example. 1 of categories called pages, text inside selectbox in code above shows ["pages", 1] 1 id.
any appreciated :)
i think correct syntax below
= f.select :category_id, options_for_select(category.collect {|c| [c.name, c.id]}), { :include_blank => "please select category"}, {:class => "form-control"}
Comments
Post a Comment