Select_tag - populating options


#1

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


#2

this works:

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

don’t forget the ‘@’


#3

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


#4

this will definitely work:

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

the error should come from other parts of your code


#5

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


#6

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


#7

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/


#8

Rimantas L. wrote:

Why not like this:

model:
LINE_QTY = (1…100).to_a

Fantastic - exactly what I was looking for !

Cheers,

/mich