Re: can''t convert hash into integer

dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2006-09-26T15:57:00Z

Hi --

On Tue, 26 Sep 2006, Ianne Leson wrote:

>
> sorry for the incomplete info.  Here''re the details:
>
> #I''ve construct the data object in the controller:
> for i in 0..10
>  @option[i] = {
>    :name => @params[("name"+i.to_s).to_sym],
>    :value => @params[("value"+i.to_s).to_sym]
>  }
> end
>
> #then pass the object to model function
> Somemod.funct(
>  ...some other parameters...
>  :option => @option)
>
> #this is the model function
> self.funct(input)
> .......
> input[:option].each do |opt_k|
>  options[opt_k] = Hash.new(0)
>  options[opt_k] = OtherClass.new(input[:option][opt_k])

You''re assigning to options[opt_k] twice, which means the first
assignment will get clobbered.

> end unless input[:option].nil?
>
> #I suspect that the problem is assoc with input[:option][opt_k], which
> returns error when I want to put it on screen

That sounds right.  input[:option] is an array, and you''re trying to
index it with a hash (opt_k) instead of an integer.  (I''m assuming
options is a hash; if it''s an array, then you''ve got the same
problem
there too.)

I''m not clear on what you''re trying to do in that each loop,
so I''m
not sure what the right code would be, but you''ll need to make sure
not to use a hash to index an array.


David

--
                   David A. Black |
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
Author of "Ruby for Rails"   [1] | Ruby/Rails training &
consultancy [3]
DABlog (DAB''s Weblog)        [2] | Co-director, Ruby Central, Inc.
[4]
[1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com    | [4] http://www.rubycentral.org