Schienen select_tag - Einstellung include_blank und Auswahl einer default-Wert

select_tag :country_id, options_from_collection_for_select(Country.order('priority desc, name asc'), "id", "name"), { :prompt => 'Select a country', :include_blank => 'None' } %> 

Funktioniert wie erwartet, außer :include_blank => 'None'. Macht eine leere option. Wie Z:

<option value=""></option>

Zweite, mit der select_tag. Wie kann ich einen Standardwert angeben. Zum Beispiel, wenn ich die select-box zum auswählen eines bestimmten Landes. Ich habe versucht, das hinzufügen :selected => Country.first ohne Erfolg:

<%= select_tag :country_id, options_from_collection_for_select(Country.order('priority desc, name asc'), "id", "name"), { :prompt => 'Select` a country', :include_blank => 'None', :selected => Country.first } %>

Oben immer wählt "Select a country".

Warum?

Schreibe einen Kommentar