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.
Adb3e4d29fba0d4360f225eba6ba47d7?d=identicon&s=25 mich (Guest)
on 2006-04-05 10: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 Development 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
36958dd94ca666a38483df282a5214d5?d=identicon&s=25 Peter Ertl (Guest)
on 2006-04-05 10:55
(Received via mailing list)
this works:

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

don't forget the '@'
Adb3e4d29fba0d4360f225eba6ba47d7?d=identicon&s=25 mich (Guest)
on 2006-04-05 11:02
Peter Ertl 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
36958dd94ca666a38483df282a5214d5?d=identicon&s=25 Peter Ertl (Guest)
on 2006-04-05 11: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
Adb3e4d29fba0d4360f225eba6ba47d7?d=identicon&s=25 mich (Guest)
on 2006-04-05 11:22
Peter Ertl 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
36958dd94ca666a38483df282a5214d5?d=identicon&s=25 Peter Ertl (Guest)
on 2006-04-05 11:32
(Received via mailing list)
%w{a b c} can be easily replaced with an instance variable @options.
Ec5a599777854c540fd102ef4691fe10?d=identicon&s=25 Rimantas Liubertas (Guest)
on 2006-04-05 11: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/
Adb3e4d29fba0d4360f225eba6ba47d7?d=identicon&s=25 mich (Guest)
on 2006-04-05 11:57
Rimantas Liubertas 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.