# Need a little push in the right direction. @prices = [ "amazon_new" => [ "image" => "imageurl.com", "url" => "bookurl.com", "price" => 45.55 ], "amazon_used" => [ "image" => "2ndImageUrl.com", "url" => "2ndbookurl.com", "price" => 67.45 ] ] @prices.each do |p| p.each do |x| x["image"] # Can''t convert string into integer. end end -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/d2d1f766-1af9-40a5-9d66-45b34037e5b0%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
On Thu, Jun 20, 2013 at 10:30 AM, Patrick Curl <patrickwcurl-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> # Need a little push in the right direction. > @prices = [ > "amazon_new" => [ > "image" => "imageurl.com", > "url" => "bookurl.com", > "price" => 45.55 > ], > > "amazon_used" => [ > "image" => "2ndImageUrl.com", > "url" => "2ndbookurl.com", > "price" => 67.45 > ] > ] > > @prices.each do |p| > p.each do |x| > x["image"] > # Can''t convert string into integer. > >You get this error when you try to access an array as a hash. ie array = (1..4).to_a array[''image''] # can''t convert string into integer try to look again at how @prices is declared. judging from the code you pasted, you want @prices to be a hash but it''s using square braces.> end > end > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/d2d1f766-1af9-40a5-9d66-45b34037e5b0%40googlegroups.com > . > For more options, visit https://groups.google.com/groups/opt_out. > > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAJ8y7VfhbBBtyY%3DpqyD6x%3DQWuJoRWx7M3W%3Djc4WVQJReyGYo_g%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
You are mixing up arrays and hashes. Below is an all hash example. @prices = { "amazon_new" => { "image" => "imageurl.com", "url" => "bookurl.com", "price" => 45.55 }, "amazon_used" => { "image" => "2ndImageUrl.com", "url" => "2ndbookurl.com", "price" => 67.45 } } @prices.each_pair do |type, data| puts "#{type} : #{data[''image'']}" end and here is an array / hash example @prices = [ { "image" => "imageurl.com", "url" => "bookurl.com", "price" => 45.55 }, { "image" => "2ndImageUrl.com", "url" => "2ndbookurl.com", "price" => 67.45 } ] @prices.each do |data| puts data[''image''] end On 20/06/13 11:30, Patrick Curl wrote:> # Need a little push in the right direction. > @prices = [ > "amazon_new" => [ > "image" => "imageurl.com", > "url" => "bookurl.com", > "price" => 45.55 > ], > "amazon_used" => [ > "image" => "2ndImageUrl.com", > "url" => "2ndbookurl.com", > "price" => 67.45 > ] > ] > @prices.each do |p| > p.each do |x| > x["image"] > # Can''t convert string into integer. > end > end > -- > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/d2d1f766-1af9-40a5-9d66-45b34037e5b0%40googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/51C27144.5060600%40toppan-f.co.jp. For more options, visit https://groups.google.com/groups/opt_out.