From: Julian Leviston Date: 2008-04-03T16:50:41+09:00 Subject: Re: ArgumentError even if variable is set That's because your params["numdomains"] is returning a blank array, so technically it's not empty. to_i is a method of the string class. you could put params["numdomains"].to_s.to_i But I don't know why your numdomains is returning an array?? Julian Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW VIDEO (#2) OUT NOW! http://sensei.zenunit.com/ On 03/04/2008, at 6:44 PM, Prabhas Gupte wrote: > Julian Leviston wrote: >> This is because cgi.params["numdomains"] will return a string. >> >> As a range can't be from a number to a string, you get the following >> problem: >> >> in irb: >>>> (0.."30") >> ArgumentError: bad value for range >> from (irb):1 >> >> What you need to do is run "to_i" on the string. >> >> unless cgi.params['numdomains'].empty? then >> $numdomains = cgi.params['numdomains'].to_i >> else >> $numdomains = 3 >> end >> >> That should fix your problem. >> >> Julian. >> >> Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW VIDEO >> (#2) OUT NOW! >> http://sensei.zenunit.com/ > > > --------------------------------------------------------- > If I do cgi.params['numdomains'].to_i then it returns another error: > undefined method `to_i' for []:Array (NoMethodError) > > -- > Posted via http://www.ruby-forum.com/. >