Hi, I have the following code in model: input[:hello].each do |abc| blablablab end and it terminated with error "can''t convert hash into integer" anyone has got a clue? Thanks. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2006-Sep-26 11:48 UTC
Re: can''t convert hash into integer
Hi -- On Tue, 26 Sep 2006, Ianne Leson wrote:> > Hi, > > I have the following code in model: > > input[:hello].each do |abc| > blablablab > end > > and it terminated with error "can''t convert hash into integer" > > anyone has got a clue? Thanks.My first suspicion is that, somewhere, you''re trying to use a hash where you need an integer :-) But "blablablab", and no information about what line the error pointed to, makes it hard to say much more. 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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]) ................ 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 Thanks. unknown wrote:> Hi -- > > On Tue, 26 Sep 2006, Ianne Leson wrote: > >> >> anyone has got a clue? Thanks. > > My first suspicion is that, somewhere, you''re trying to use a hash > where you need an integer :-) But "blablablab", and no information > about what line the error pointed to, makes it hard to say much more. > > > 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-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2006-Sep-26 15:57 UTC
Re: can''t convert hash into integer
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 screenThat 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---