KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to build a hash from a Model. This is the type of hash I want to build. {"United Sates" => "us", "United Kingdom" => "uk" .....} I have tried so many ways now I'm just going around in circles. Here are just some of my poor attempts. select = Array.new countries.each do |country| # select.push({country.name => country.code }) # select[country.name][country.code] end h = {} countries.each do |c| # h[] = {c.name => c.code} # h[] ||= {} # h[][:name] = c.name # h[][:code] = c.code #h[r.grouping_id][:name] = r.name # h[r.grouping_id][:description] = r.description end Please can some advise. Thank You
Tags (comma-separated)
Save Edits
Cancel