Creating looped pulldowns in PHP is simple so I can''t figure out why it seems to elude me in RoR. I want to create a simple pulldown list with the options and values "1" through "14." I have been trying to accomplish this with the .upto method like so: --START RHTML CODE-- <% options_array = [ 1.upto(14) {|i| print "[" i "," i "]"} ] %> <%= select(''radical'', ''strokes'', options_array) %> --END CODE-- I have tried variations of parenthesis and quotations to no avail. At best, I can generate [1,1] but nothing further. Of course I could have just done this by hand in less than a quarter of the time I''ve been working on using .upto() but I''m stubborn! Advice would be greatly appreciated! Taylor -- Posted via ruby-forum.com.
On 6/3/06, Taylor Strait <taylorstrait@gmail.com> wrote:> Creating looped pulldowns in PHP is simple so I can''t figure out why it > seems to elude me in RoR. I want to create a simple pulldown list with > the options and values "1" through "14." > > I have been trying to accomplish this with the .upto method like so: > > --START RHTML CODE-- > <% options_array = [ > 1.upto(14) {|i| print "[" i "," i "]"} > ] %> > > <%= select(''radical'', ''strokes'', options_array) %> > > --END CODE-- > > I have tried variations of parenthesis and quotations to no avail. At > best, I can generate [1,1] but nothing further. Of course I could have > just done this by hand in less than a quarter of the time I''ve been > working on using .upto() but I''m stubborn! Advice would be greatly > appreciated!You can''t use "print" inside of RHTML templates (well, you can, but it''s ugly, and not as pretty as what you pasted.) <%= select ''radical'', ''strokes'', (1..14).to_a %> ..would be one way to do it. (1..14) is a range of numbers, 1 to 14.. ''to_a'' turns it into an Array. Sounds like you''re making a Japanese dictionary app? If you really wanted to use upto, you could do it this way (which I don''t recommend, because it''s longer.) options_array = [] 1.upto(14) {|i| options_array << [i,i]}
On Sunday, June 04, 2006, at 3:36 AM, Taylor Strait wrote:>Creating looped pulldowns in PHP is simple so I can''t figure out why it >seems to elude me in RoR. I want to create a simple pulldown list with >the options and values "1" through "14." > >I have been trying to accomplish this with the .upto method like so: > >--START RHTML CODE-- ><% options_array = [ >1.upto(14) {|i| print "[" i "," i "]"} >] %> > ><%= select(''radical'', ''strokes'', options_array) %> > >--END CODE-- > >I have tried variations of parenthesis and quotations to no avail. At >best, I can generate [1,1] but nothing further. Of course I could have >just done this by hand in less than a quarter of the time I''ve been >working on using .upto() but I''m stubborn! Advice would be greatly >appreciated! > >Taylor > >-- >Posted via ruby-forum.com. >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >lists.rubyonrails.org/mailman/listinfo/railstry <%= select ''radical'',''strokes'', (1..14).map %> _Kevin -- Posted with DevLists.com. Sign up and save your mailbox.
On Sunday, June 04, 2006, at 2:10 AM, Kevin Olbrich wrote:> >On Sunday, June 04, 2006, at 3:36 AM, Taylor Strait wrote: >>Creating looped pulldowns in PHP is simple so I can''t figure out why it >>seems to elude me in RoR. I want to create a simple pulldown list with >>the options and values "1" through "14." >> >>I have been trying to accomplish this with the .upto method like so: >> >>--START RHTML CODE-- >><% options_array = [ >>1.upto(14) {|i| print "[" i "," i "]"} >>] %> >> >><%= select(''radical'', ''strokes'', options_array) %> >> >>--END CODE-- >> >>I have tried variations of parenthesis and quotations to no avail. At >>best, I can generate [1,1] but nothing further. Of course I could have >>just done this by hand in less than a quarter of the time I''ve been >>working on using .upto() but I''m stubborn! Advice would be greatly >>appreciated! >> >>Taylor >> >>-- >>Posted via ruby-forum.com. >>_______________________________________________ >>Rails mailing list >>Rails@lists.rubyonrails.org >>lists.rubyonrails.org/mailman/listinfo/rails > >try > ><%= select ''radical'',''strokes'', (1..14).map %> > >_Kevin > >-- >Posted with DevLists.com. Sign up and save your mailbox. >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >lists.rubyonrails.org/mailman/listinfo/railsoops, the ''map'' isn''t necessary <%= select ''radical'',''strokes'', (1..14) %> _Kevin -- Posted with DevLists.com. Sign up and save your mailbox.
<%= select ''radical'',''strokes'', (1..14) %> Amazing. This worked like a charm. Thanks for all the suggestions. I knew RoR was supposed to be faster than PHP. If only there were some good resources for beginners! (yes I have the PickAxe/Agile) I am developing a Japanese character app as I learn rails so expect more rookie questions fomr me. Thanks a lot! Taylor -- Posted via ruby-forum.com.
<%= select ''radical'',''strokes'', (1..14) %> Amazing. This worked like a charm. Thanks for all the suggestions. I knew RoR was supposed to be faster than PHP. If only there were some good resources for beginners! (yes I have the PickAxe/Agile) I am developing a Japanese character app as I learn rails so expect more rookie questions from me. Thanks a lot! Taylor -- Posted via ruby-forum.com.