Reputation: 89
I have a select_tag in ruby on rails. The syntax for this is,
<%= select_tag "iso_region", options_for_select(@all_regions.collect {|p| [ "#{p['cc']}-#{p['lr']}", p['cc'] ] }), class: "form-control selectpicker reg_name", :data => {:'live-search' => 'true'} %>
Sample Options generated is like this,
<option value="ET">ET-Africa</option>
<option value="NG">NG-Africa</option>
<option value="PG">PG-Pacific</option>
<option value="IT">IT-Europe</option>
And I want IT-Europe to be selected in the dropdown. How can I do that with my select_tag?
Upvotes: 0
Views: 238
Reputation: 714
Try this:
options_for_select(@all_regions.collect {|p| [ "#{p['cc']}-#{p['lr']}", p['cc'] ] }, "IT"),
The last arg you pass to options_for_select
is the value to be marked selected when it's rendered.
Upvotes: 1