Rails:在select()帮助器中手动更改选项的顺序?

时间:2010-07-21 21:37:07

标签: ruby-on-rails select helper

我有以下select()表单帮助方法:

select("treatment", "frequency_unit", { "hour" => "hour", "day" => "day", "week" => "week", "month" => "month", "year" => "year" })

帮助者正在组织看似随机的选择...我希望它能保持选择的顺序,就像上面列出的那样。

我怎样才能实现这一目标?

以下是上述代码的输出:

<select id="treatment_frequency_unit" name="treatment[frequency_unit]">
  <option value="month">month</option>
  <option value="week">week</option>
  <option value="hour">hour</option>
  <option value="day">day</option>
  <option value="year">year</option>
</select>

1 个答案:

答案 0 :(得分:1)

而不是哈希,去一个数组

<%= select("treatment", "frequency_unit", %w{hour day week month year})%>