# Creating pulldowns using loops

**URL:** <https://www.ruby-forum.com/t/creating-pulldowns-using-loops/62402>\
**Category:** Rails\
**Created:** [June 4, 2006, 3:36am UTC](https://www.ruby-forum.com/t/creating-pulldowns-using-loops/62402 "2006-06-04T03:36:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [June 4, 2006, 3:36am UTC](https://www.ruby-forum.com/t/creating-pulldowns-using-loops/62402/1 "2006-06-04T03:36:01Z")

</div>

Creating looped pulldowns in PHP is simple so I can’t figure out why it  
seems to elude me in RoR. I want to create a simple pulldown list with  
the options and values “1” through “14.”

I have been trying to accomplish this with the .upto method like so:

–START RHTML CODE–  
\<% options\_array = [  
1.upto(14) {|i| print “[” i “,” i “]”}  
] %\>

\<%= select(‘radical’, ‘strokes’, options\_array) %\>

–END CODE–

I have tried variations of parenthesis and quotations to no avail. At  
best, I can generate [1,1] but nothing further. Of course I could have  
just done this by hand in less than a quarter of the time I’ve been  
working on using .upto() but I’m stubborn! Advice would be greatly  
appreciated!

Taylor

---

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [June 4, 2006, 4:02am UTC](https://www.ruby-forum.com/t/creating-pulldowns-using-loops/62402/2 "2006-06-04T04:02:35Z")

</div>

On 6/3/06, Taylor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%= select(‘radical’, ‘strokes’, options\_array) %\>
> 
> –END CODE–
> 
> I have tried variations of parenthesis and quotations to no avail. At  
> best, I can generate [1,1] but nothing further. Of course I could have  
> just done this by hand in less than a quarter of the time I’ve been  
> working on using .upto() but I’m stubborn! Advice would be greatly  
> appreciated!

You can’t use “print” inside of RHTML templates (well, you can, but  
it’s ugly, and not as pretty as what you pasted.)

\<%= select ‘radical’, ‘strokes’, (1…14).to\_a %\>  
…would be one way to do it. (1…14) is a range of numbers, 1 to 14…  
‘to\_a’ turns it into an Array.

Sounds like you’re making a Japanese dictionary app?

If you really wanted to use upto, you could do it this way (which I  
don’t recommend, because it’s longer.)  
options\_array = []  
1.upto(14) {|i| options\_array \<\< [i,i]}

---

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [June 4, 2006, 4:11am UTC](https://www.ruby-forum.com/t/creating-pulldowns-using-loops/62402/3 "2006-06-04T04:11:59Z")

</div>

On Sunday, June 04, 2006, at 3:36 AM, Taylor S. wrote:

> Taylor
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

try

\<%= select ‘radical’,‘strokes’, (1…14).map %\>

\_Kevin

---

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [June 4, 2006, 4:27am UTC](https://www.ruby-forum.com/t/creating-pulldowns-using-loops/62402/4 "2006-06-04T04:27:59Z")

</div>

\<%= select ‘radical’,‘strokes’, (1…14) %\>

Amazing. This worked like a charm. Thanks for all the suggestions. I  
knew RoR was supposed to be faster than PHP. If only there were some  
good resources for beginners! (yes I have the PickAxe/Agile) I am  
developing a Japanese character app as I learn rails so expect more  
rookie questions fomr me. Thanks a lot!

Taylor

---

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [June 4, 2006, 4:15am UTC](https://www.ruby-forum.com/t/creating-pulldowns-using-loops/62402/5 "2006-06-04T04:15:12Z")

</div>

On Sunday, June 04, 2006, at 2:10 AM, Kevin O. wrote:

> > 1.upto(14) {|i| print “[” i “,” i “]”}  
> > appreciated!  
> > try  
> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)  
> > oops, the ‘map’ isn’t necessary

\<%= select ‘radical’,‘strokes’, (1…14) %\>

\_Kevin

---

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [June 4, 2006, 4:28am UTC](https://www.ruby-forum.com/t/creating-pulldowns-using-loops/62402/6 "2006-06-04T04:28:20Z")

</div>

\<%= select ‘radical’,‘strokes’, (1…14) %\>

Amazing. This worked like a charm. Thanks for all the suggestions. I  
knew RoR was supposed to be faster than PHP. If only there were some  
good resources for beginners! (yes I have the PickAxe/Agile) I am  
developing a Japanese character app as I learn rails so expect more  
rookie questions from me. Thanks a lot!

Taylor
