Rails - 添加要选择的自定义项

时间:2013-06-13 14:44:10

标签: ruby-on-rails

我有这行代码:

<%= select "family", "num_of_children", (1..10), { :include_blank => true } %>

我想在列表末尾添加一个项目。在这种情况下:我想要一个“更多”选项作为最后一项。 我怎么能这样做?

2 个答案:

答案 0 :(得分:2)

将范围转换为数组,然后将'more'追加到它:

<%= select "family", "num_of_children", (1..10).to_a << 'more', { :include_blank => true } %>

答案 1 :(得分:1)

<%= select "family", "num_of_children", (1..10).to_a + [['more', '11']], { :include_blank => true } %>