score:7

Accepted answer

I solved my question by remapping my hash to a new array. Seems like it might be possible to do this with an original query, but I am not strong on Activerecord/SQL to make it happen.

Here is how I remapped the hash to an array of objects that could be used with D3-generator in Ruby

@referral_source = Client.count(:all, :group => :referral_source)
remap = @referral_source.map {|k, v| { Name: k, Count: v} } 

=> {{:Name=>"Internet search (e.g., Google)?", :Count=>26}, ... ]

Then I did a .to_json on that in the view. It took me a lot longer than I thought it would to figure out.


Related Query

More Query from same tag