richard
1
Hi,
What is a nice, easy, one-line method of populating a selection list
with numbers in rails?
So far I can populate an array with the numbers I want using a loop:
<% opts = []
26.times do |x|
opts << [x, x]
end
-%>
and then use the opts array for the options in the select helper.
But is there a better way?
Thanks for any suggestions,
Richard
richard
2
i just learned this
<% opts = Array.new(26) {|x| [x,x]} %>
perhaps it could be used this way too? (not positive)
<%= select ‘talent’, ‘age’, Array.new(26) {|x| [x,x]} %>
hope this helps,
Oliver
2005/11/21, Richard [email protected]:
richard
3
Richard <richard.mcgrath@…> writes:
and then use the opts array for the options in the select helper.
But is there a better way?
Here’s how I do it. . .
<%= select_tag :choice, options_for_select(0…30, @params[:choice]) %>
–Forrest
richard
4
Thanks Oliver, that worked a treat!
(Using the method inside the select-tag helper function)
Regards,
Richard
ol1barn3s wrote:
i just learned this
<% opts = Array.new(26) {|x| [x,x]} %>
perhaps it could be used this way too? (not positive)
<%= select ‘talent’, ‘age’, Array.new(26) {|x| [x,x]} %>
hope this helps,
Oliver
2005/11/21, Richard [email protected]:
richard
5
It’s probably still not quite what you’re after, but you can shorten
your code to:
(1..26).collect {|x| [x, x] }
and put that directly inside the call to select.
Cheers,
Pete Y.
richard
6
hehehe
god bless ruby… still a beginner in it, but already love it
2005/11/22, Ryan R. [email protected]:
thank goodness for search feature working well!
actually im stuck again…what is the correct line of code if i
initialize my form with a model called :temp with a filed called
‘num_days’?
i have this but not working
<%= select_tag :temp, options_for_select(0…30, :expnum) %>
i am getting a undefined method `stringify_keys!’ for “5”:String…
thanks
no boss
i am not getting any error
its working fine
by
richard
10
or just (1…26).to_a
-r
–
Ryan R.
http://www.rockefeller.edu – Bacterial Pathogenesis and Immunology
http://www.worldmartial.com – Black Belt Instructor
http://locomotive.sourceforge.net – Self contained one-click Rails for
Mac OS X