How do I iterate over a range in ERB?

302 views Asked by At

I'm trying to generate a dropdown with the alphabet in it. Weird, I know, I'm making an old school arcade style name selector for a game (3/4 letters) selectable with arrow keys.

So far I've got this:

<%= select_tag(:letters) do %>
    <% ('A'..'Z').each do |letter| %>
      <%= content_tag(:option, letter, value: letter) %>
    <% end %>
<% end %>

I'm getting the <select> tag, but the option tags are not generated. I'm sure it's just a small syntax error but I'm stumped.

1

There are 1 answers

0
nesiseka On BEST ANSWER

The following should work:

<%= select_tag(:letters, options_for_select(('A'..'Z').to_a)) %>