我有以下表格:
<%= 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 %>
当我提交表格时,我最终会:
www.example.com/users?country=US
我希望表单能够预选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 %>
答案 0 :(得分:1)
没关系,我用这个答案解决了这个问题:
How to make the select_tag keep value of last search?
:selected => params[:country]