options_for_selectでselectedできない
モデルに関係ない検索で、$hogesに選択肢配列を作っておいて、プルダウンメニューを操作したら結果を返すような仕組みで、selectedがどうしても出来なかったのでググるとoptions_for_select(選択肢、selected)とすると動いた。
#search.html.erb <%= form_tag :action => "search" do%> <%= select_tag(:hoge, options_for_select($hoges, :selected=>@hoge), :include_blank=>true , :onchange => 'this.form.submit()')%> <% end %>
def search @hoge = params[:hoge] ? params[:hoge] : "" end