class SwitchesController < ApplicationController #before_filter :authenticate_user!, :except => [:index, :show] def index end def show end #存储拓扑 def topo @vts = VmToSwitch.all @sts = SwitchToSwitch.all @stvs = SwitchToVswitch.all end #监控 def monitor @switches = [["S1","s1v"],["S2","s2v"]] @select_value = params[:people] end end
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <%= render partial: ‘bar‘ %> <b>hello monitor</b> <%= form_tag("monitor") do |f| %> <%= select_tag "people", options_for_select(@switches), prompt: "Select something" %> <%= submit_tag("Search") %> <% end %> </br> <b>your choice:</b> <%= @select_value %>
突然才发现form_for 和 form_tag是有区别的
form_tag 可以不用绑定model类直接取得数据。。。对于简单的这种选择响应再好不过
form_for能不能不绑定model还有待学习
原文:http://www.cnblogs.com/juandx/p/3896160.html