我的select_tag
options_for_select
看起来像这样:
<%= select_tag "respondent", options_for_select(1..5, 2) %>
输出:
<select id="respondent" name="respondent">
<option value="1">1</option>
<option value="2" selected="selected">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
但我希望它输出的是:
<select id="respondent" name="respondent">
<option value="/arbitrary/page/1">#1</option>
<option value="/arbitrary/page/2" selected="selected">#2</option>
<option value="/arbitrary/page/3">#3</option>
<option value="/arbitrary/page/4">#4</option>
<option value="/arbitrary/page/5">#5</option>
</select>
我该如何解决这个问题?
答案 0 :(得分:1)
如果您有arbitrary_page_path
这样的命名路线:
<% collection = (1..5).map { |i| ["##{i}", arbitrary_page_path(i)] } %>
<%= select_tag "respondent", options_for_select(collection, arbitrary_page_path(2)) %>