5
目前我使用的是選擇如下
(表單中):Ruby on Rails的選擇不默認爲當前值
<% 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。我該如何解決這個問題?
自動選擇當前值適用於單選按鈕:
<% 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 %>
任何幫助,得到這個工作將不勝感激!
對不起 - 我應該pairs_name_id的陣列樣子..? – tiswas 2011-01-26 17:20:33