Assign id to simple form collection options

30 Views Asked by At

New developer trying to assign an different ids to Round Oval and Banana options, so can initiate action on select:

<%= f.input :content, label: 'Fruit Shape', :collection => %w[Round Oval Banana] %>

but all options always have the id 'update_content', I assume due to instance of Update.

$('#Round').on('click', function(){
    $("#round_div").show();
  })

Fails. From research I have tried:

:collection => %w[Round Oval Banana].map { |category| [category, {:id => category}]}

which generates

<select class="form-control select optional valid" name="update[content]" id="update_content" aria-invalid="false"><option value="">SELECT</option>
<option id="Round" value="Round">Round</option>
<option id="Oval" value="Oval">Oval</option>
<option id="Banana" value="Banana">Banana</option></select>

and other variations such as:

collection: [["Round", {:id => "round"}], ["Oval", {:id => "oval"}], ["Banana", {:id => "banana"}]],

but the round_div doesn't show

0

There are 0 best solutions below