From: Matthew Williams Date: 2008-01-29T06:26:21+09:00 Subject: Re: Assistance dynamically building a nested hash > > My code: > > @actuals = Actual.find(:all, :select => 'obs_number, week_ending, > labor_hours', :conditions => ["week_ending >= ? AND project_number = ? > AND primary_number = ?", @week_ending, @charge.project_number, > @charge.primary_number]).to_a > > results = Hash.new do |hash, key| > hash[key] = {} > end > > @actuals.each do |sub_arr| > main_key = sub_arr[0] > sub_key = sub_arr[1] > #Create new key, value in sub hash: > results[main_key][sub_key] = sub_arr[2] > end > > After that runs I'm left with results as a single hash with no data. > I'll continue with the debugging and hopefully end up with a successful > result soon enough. Thanks for the responses! > sub_arr was being treated as an actual object data type... So a few quick changes to sub_arr to reference the attributes instead of indexes and I'm all set. I'm still working on my iterator to appropriately sort through them in my view but I appreciate the help a lot on getting the ball rolling... Take care. -- Posted via http://www.ruby-forum.com/.