0
私は次の形式をしている:options_from_collection_for_selectであらかじめ選択する方法は?
www.example.com/users?country=US
私は希望:私はフォームを送信すると
<%= form_tag users_path, method: :get, id: 'uco' do %>
<%= select_tag "country", options_from_collection_for_select(ISO3166::Country.countries.sort_by(&:name), 'un_locode', 'name'), :include_blank => true %>
<%= submit_tag "Search" %>
<% end %>
は私がで終わります次に、事前選択するフォームのようにparams[:country]
を選択します。
しかし、params[:country]
をselect_tagに添付する方法はわかりません。私は失敗してみました:
<%= select_tag "country", options_from_collection_for_select(ISO3166::Country.countries.sort_by(&:name), 'un_locode', 'name', params[:country]), :include_blank => true %>
this example from the apidock.