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 -- Posted via http://www.ruby-forum.com/.
this works: <%= select("rfq_line", "line_qty", @options) %> don''t forget the ''@''> --- Urspr?ngliche Nachricht --- > Von: mich <nospam@thanks.com> > An: rails@lists.rubyonrails.org > Betreff: [Rails] select_tag - populating options > Datum: Wed, 5 Apr 2006 10:47:22 +0200 > > 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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
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 -- Posted via http://www.ruby-forum.com/.
this will definitely work: <%= select("person", "name", %w{Peter Paul Mary}) %> the error should come from other parts of your code> --- Urspr?ngliche Nachricht --- > Von: mich <nospam@thanks.com> > An: rails@lists.rubyonrails.org > Betreff: [Rails] Re: select_tag - populating options > Datum: Wed, 5 Apr 2006 11:02:38 +0200 > > 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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Peter Ertl wrote:> this will definitely work: > > <%= select("person", "name", %w{Peter Paul Mary}) %> > > the error should come from other parts of your codeYes, 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 -- Posted via http://www.ruby-forum.com/.
%w{a b c} can be easily replaced with an instance variable @options.> --- Urspr?ngliche Nachricht --- > Von: mich <nospam@thanks.com> > An: rails@lists.rubyonrails.org > Betreff: [Rails] Re: Re: select_tag - populating options > Datum: Wed, 5 Apr 2006 11:22:09 +0200 > > 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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
> 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/