我目前在表单中使用以下选择器:
<% form_for :search, :url => search_path, :html => {:method => :get} do |f| %>
<%= select('search', :type, options_for_select(['Artist', 'Track'])) %>
<%= f.text_field :query %>
<% end %>
这个方法可行,但是当我执行搜索时,即使用户在搜索前选择了“Track”,它仍会默认回到“artist”。我该怎么解决?
对于单选按钮,自动选择当前值是可行的:
<% form_for @search, :url => search_path, :html => {:method => :get} do |f| %>
<p class="radio_button">
<%= f.label :type_track, 'Search tracks' %>
<%= f.radio_button :type, 'Track' %>
</p>
<p class="radio_button">
<%= f.label :type_artist, 'Search artists' %>
<%= f.radio_button :type, 'Artist' %>
</p>
<p class="text_field">
<%= f.label :query, 'Search query' %>
<%= f.text_field :query, :class => 'auto_focus' %>
</p>
<p class="submit">
<%= submit_tag 'Go' %>
</p>
<% end %>
任何有助于让这个工作的帮助都将不胜感激!