Jimmy Lynn
Jimmy Lynn

Reputation: 65

How to add an HTML argument to a Rails select helper using chosen-select

I would like to use Multiple select with chosen with Rails 4.

<%= f.select :card_details,
  CardDetail.all.map { |cd| [cd.name, cd.id] },
               { include_blank: true },
               { class: 'chosen-select' }
%>

How can I add "multiple" to the HTML argument?

Right now, it renders this:

<select class="chosen-select" name="card[card_details]" id="card_card_details">

I want to add multiple in that line:

<select class="chosen-select" name="card[card_details]" multiple id="card_card_details">

Upvotes: 0

Views: 44

Answers (1)

vee
vee

Reputation: 38645

Use multiple: true within the HTML options as follows:

<%= f.select :card_details,
  CardDetail.all.map { |cd| [cd.name, cd.id] },
               { include_blank: true },
               { class: 'chosen-select', multiple: true }
%>

Upvotes: 2

Related Questions