Reputation: 284
I'm wanting to implement Bootstrap's dropdowns in my rails project similar to the 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 currently have a section in the project where I can add new/edit categories for use in the main form. The code I currently have for an unformatted select/dropdown is:
<%= f.select :category_id, Category.all.map { |category| [ category.name, category.id ] }, class: "form-control" %>
Which doesn't seem to apply any bootstrap formatting, I've tried changing the code around a bit to be:
<%= f.select :category_id, options_for_select([Category.all.map { |category| [ category.name, category.id ] }]), {}, class: "form-control" %>
This gives the dropdown box a bootstrap style box, but the dropdowns under the default selection don't have any formatting similar to Bootstrap's example. One of my categories is just called Pages, but the text inside the selectbox in the code above just shows ["pages", 1] where 1 is the ID.
Any help with this would be greatly appreciated :)
Upvotes: 1
Views: 3111
Reputation: 1974
i think correct syntax is like below
= f.select :category_id, options_for_select(Category.collect {|c| [c.name, c.id]}), { :include_blank => "Please select category"}, {:class => "form-control"}
Upvotes: 5