Forum: Ruby on Rails select_tag - populating options

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
mich (Guest)
on 2006-04-05 12:47
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
Peter E. (Guest)
on 2006-04-05 12:55
(Received via mailing list)
this works:

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

don't forget the '@'
mich (Guest)
on 2006-04-05 13:02
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
Peter E. (Guest)
on 2006-04-05 13:20
(Received via mailing list)
this will definitely work:

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

the error should come from other parts of your code
mich (Guest)
on 2006-04-05 13:22
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
Peter E. (Guest)
on 2006-04-05 13:32
(Received via mailing list)
%w{a b c} can be easily replaced with an instance variable @options.
Rimantas L. (Guest)
on 2006-04-05 13:45
(Received via mailing list)
> 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/
mich (Guest)
on 2006-04-05 13:57
Rimantas L. wrote:

>
> Why not like this:
>
> model:
> LINE_QTY = (1..100).to_a


Fantastic - exactly what I was looking for !

Cheers,

/mich
This topic is locked and can not be replied to.