rails select_tag 选定值 [英] rails select_tag selected value
本文介绍了rails select_tag 选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于下面给出的代码,我想使用传递的值保持选中的选择框.
For the code given below I wanted to keep the select box selected with the value that is passed.
但这不起作用:
@yrs =[2011,2010,2009,2008]
<%= select_tag 'year', options_for_select([["Select" , "" ]] + @yrs.to_a,:selected=>2011) %>
请告诉我如何去做.
谢谢
推荐答案
删除 :selected=>
部分.
语法:
options_for_select(@options, @selected_options)
用法:
options_for_select(1..5, 3) # creates a range 1..5 , with 3 as selected by default
这篇关于rails select_tag 选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文