Looping through hash and sub-hash.

# 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

# 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.

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