0

So, new to ruby and struggling on this:

images table - 2 columns, filename and md5 using the mysql2 extension

images = Hash.new
results = client.query("SELECT * FROM images").each do |row|
    images[row['filename']] = row['md5']
end

i'd like to just do this automatically, it seems pointless to loop through to make a hash - I think that I have missed something ?

1 Answers1

0

You can try following

images = Hash[*Image.all.map{ |i| [i.filename, i.md5] }.flatten]
Salil
  • 46,566
  • 21
  • 122
  • 156