Select_tag - populating options

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

this works:

<%= select(“rfq_line”, “line_qty”, @options) %>

don’t forget the ‘@’

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

this will definitely work:

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

the error should come from other parts of your code

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

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

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/

Rimantas L. wrote:

Why not like this:

model:
LINE_QTY = (1…100).to_a

Fantastic - exactly what I was looking for !

Cheers,

/mich