On Thu, Sep 30, 2010 at 5:39 AM, Wesley Chen cjq@gmail.com wrote:
I tried your suggestion, but I didn't find the solution.
You still did not say what is the problem! :)
What did you try? Show us the code. (Remove username/password.)
Željko
--
Before posting, please read
Hi,
I am trying to populate a select list with a random value from the
list but I am not sure how I can achieve this.
Is it possible to get the contents of the select list into an array,
count how many items are in that array and select a random one?
Sorry if this is a slightly incoherent
On Thu, Sep 30, 2010 at 3:15 PM, ISmellGas guard1883-goo...@yahoo.co.uk
wrote:
Is it possible to get the contents of the select list into an array,
count how many items are in that array and select a random one?
Sure, select_list.options will return array of contents, then just pick a
random
Another option:
array[rand(array.size)]
On Thu, Sep 30, 2010 at 10:25 AM, Željko Filipin
zeljko.fili...@wa-research.ch wrote:
On Thu, Sep 30, 2010 at 3:15 PM, ISmellGas guard1883-goo...@yahoo.co.uk
wrote:
Is it possible to get the contents of the select list into an array,
count how many
Ok, I have given it a go and it seems to work. This is pretty basic so
any tips will be gratefully received!
@contents = b.select_list(:name, mydropdown).getAllContents
@length = b.select_list(:name, mydropdown).getAllContents.length
@random = Kernel.rand(@length)
@value = @conten...@random]
On Thu, Sep 30, 2010 at 4:29 PM, ISmellGas guard1883-goo...@yahoo.co.uk
wrote:
@contents = b.select_list(:name, mydropdown).getAllContents
@length = b.select_list(:name, mydropdown).getAllContents.length
You could do it this way:
@length = @contents.length
@random = Kernel.rand(@length)
@length = @contents.length
Ahhh...yes, thats a bit neater.
Why is everything in instance variables (they begin with @)?
I am not sure really. I find it easier to pick out variables when they
start with @. Is there a disadvantage doing it this way or is it just
not the done thing?
--
Before