导轨 - 返回月份的数组为选择标记 [英] Rails - return an array of months for a select tag
问题描述
我在一个应用程序,是on Rails的2.3.8,并且需要返回月份名称和数字组成的数组被插入到options_for_select声明。我已经得到了迄今样工作的,但不是真的。我做的事情这种方式,因为select语句需要一个提示,你不能在2.3.8给options_for_select默认情况下(至少据我所知)。究其原因
I'm in an app that is on Rails 2.3.8, and need to return an array of month names and numbers to be plugged into an options_for_select statement. What I've got so far is kind of working, but not really. The reason I'm doing things this way is because the select statement needs a prompt, which you can't give options_for_select by default in 2.3.8 (at least to my knowledge).
下面是我到目前为止有:
Here is what I have so far:
@months = [['-', '']]
(1..12).each {|m| @months << [[Date::MONTHNAMES[m], m]]}
所以我在寻找什么,得到返回的都是这样的选择:
So what I'm looking to get returned are options like this:
<option value="1">January</option>
<option value="2">February</option>
不过,而是我得到:
However, instead I get:
<option value="January1">January1</option>
<option value="February2">February2</option>
我是什么失踪?
推荐答案
试试这个!
@months = [['-', '']]
(1..12).each {|m| @months << [Date::MONTHNAMES[m], m]}
这篇关于导轨 - 返回月份的数组为选择标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!