select_tag in rails about selected not change and onchange()

make it more easy after http://www.cnblogs.com/juandx/p/4058399.html

1  if you want the selected is what you choose after you submit the form use javascripts, then you should do this  selected: params[:option] in options_for_select();

2  if you want to submit after you change the select tag immediately,you should use onchange: "this.form.submit();"  ofcouse the ";"  is not necessary;

<%= form_tag("monitor",:id => "idform",name: "idform",method: "get") do |f| %>
  时间间隔:
  <%= select_tag :times, options_for_select([["second","_10seconds"],["minute","_5minutes"],["hour","_hour"],["day","_day"],["week","_week"],["month","_month"],["year","_year"]] , selected: (params[:times]==nil ? "_5minutes" : params[:times]) ), onchange: "this.form.submit();" %>
        
  列数:
  <%= select_tag :col, options_for_select([["1","1"],["2","2"],["3","3"],["4","4"],["5","5"],["6","6"],["7","7"],["8","8"],["9","9"],["10","10"]], selected: (params[:col]==nil ? 2 : params[:col]) ), onchange: "this.form.submit();" %>
     
  <%= submit_tag("刷新") %>
<% end %>

  

原文地址:https://www.cnblogs.com/juandx/p/4100905.html