# Select\_tag - populating options

**URL:** <https://www.ruby-forum.com/t/select-tag-populating-options/93631>\
**Category:** Rails\
**Created:** [April 5, 2006, 10:47am UTC](https://www.ruby-forum.com/t/select-tag-populating-options/93631 "2006-04-05T10:47:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7bcc69/32.png) [@mich](https://www.ruby-forum.com/u/mich)\
**Post date:** [April 5, 2006, 10:47am UTC](https://www.ruby-forum.com/t/select-tag-populating-options/93631/1 "2006-04-05T10:47:22Z")

</div>

Hello,

I want to a select tag, where you can choose a number between 1 and 100.

My inital code is based on the examples from Agile Web D. with  
Rails, and looks like this:

view:  
\<%= options = [[“Select number of lines”, “”]] + RfqLines::LINE\_QTY  
select(“rfq\_line”, “line\_qty”, options) %\>

model:  
LINE\_QTY = select\_fill

```
def self.select_fill
    @filler = []
    1.upto(100) do |count|
        @filler << count
    end
end

```

Obviously it is not working, and I’m sure there is some easy way of  
doing it…

Many thanks in advance,

/mich

---

<div class="post-metadata">

**Author:** ![mich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7bcc69/32.png) [@mich](https://www.ruby-forum.com/u/mich)\
**Post date:** [April 5, 2006, 10:55am UTC](https://www.ruby-forum.com/t/select-tag-populating-options/93631/2 "2006-04-05T10:55:27Z")

</div>

this works:

\<%= select(“rfq\_line”, “line\_qty”, @options) %\>

don’t forget the ‘@’

---

<div class="post-metadata">

**Author:** ![mich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7bcc69/32.png) [@mich](https://www.ruby-forum.com/u/mich)\
**Post date:** [April 5, 2006, 11:02am UTC](https://www.ruby-forum.com/t/select-tag-populating-options/93631/3 "2006-04-05T11:02:38Z")

</div>

Peter E. wrote:

> \<%= select(“rfq\_line”, “line\_qty”, @options) %\>
> 
> don’t forget the ‘@’

Hmm, it still does not work - I am seeing the following error:

undefined local variable or method `select\_fill’ for RfqLines:Class

/mich

---

<div class="post-metadata">

**Author:** ![mich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7bcc69/32.png) [@mich](https://www.ruby-forum.com/u/mich)\
**Post date:** [April 5, 2006, 11:20am UTC](https://www.ruby-forum.com/t/select-tag-populating-options/93631/4 "2006-04-05T11:20:07Z")

</div>

this will definitely work:

\<%= select(“person”, “name”, %w{Peter Paul Mary}) %\>

the error should come from other parts of your code

---

<div class="post-metadata">

**Author:** ![mich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7bcc69/32.png) [@mich](https://www.ruby-forum.com/u/mich)\
**Post date:** [April 5, 2006, 11:32am UTC](https://www.ruby-forum.com/t/select-tag-populating-options/93631/5 "2006-04-05T11:32:34Z")

</div>

%w{a b c} can be easily replaced with an instance variable @options.

---

<div class="post-metadata">

**Author:** ![mich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7bcc69/32.png) [@mich](https://www.ruby-forum.com/u/mich)\
**Post date:** [April 5, 2006, 11:22am UTC](https://www.ruby-forum.com/t/select-tag-populating-options/93631/6 "2006-04-05T11:22:09Z")

</div>

Peter E. wrote:

> this will definitely work:
> 
> \<%= select(“person”, “name”, %w{Peter Paul Mary}) %\>
> 
> the error should come from other parts of your code

Yes, I am aware that it would work - but initial question was regarding  
auto population of the options, so I do not have to write:

%w{ 1 2 3 4 5 6 7 … 100}

/mich

---

<div class="post-metadata">

**Author:** ![mich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7bcc69/32.png) [@mich](https://www.ruby-forum.com/u/mich)\
**Post date:** [April 5, 2006, 11:45am UTC](https://www.ruby-forum.com/t/select-tag-populating-options/93631/7 "2006-04-05T11:45:05Z")

</div>

> I want to a select tag, where you can choose a number between 1 and 100.  
> \<…\>  
> model:  
> LINE\_QTY = select\_fill
> 
> ```
> def self.select_fill
> @filler = []
> 1.upto(100) do |count|
> @filler << count
> end
> end
> 
> ```

Why not like this:

model:  
LINE\_QTY = (1…100).to\_a

## Regards, Rimantas

[http://rimantas.com/](http://rimantas.com/)

---

<div class="post-metadata">

**Author:** ![mich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7bcc69/32.png) [@mich](https://www.ruby-forum.com/u/mich)\
**Post date:** [April 5, 2006, 11:57am UTC](https://www.ruby-forum.com/t/select-tag-populating-options/93631/8 "2006-04-05T11:57:09Z")

</div>

Rimantas L. wrote:

> Why not like this:
> 
> model:  
> LINE\_QTY = (1…100).to\_a

Fantastic - exactly what I was looking for !

Cheers,

/mich
