0

我有一个看起来像这样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>

我怎样才能做到这一点?

4

1 回答 1

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)) %>
于 2012-04-11T20:25:02.347 回答