Active Record to_hash
I find it good for programming JSON apps.
In lib/ar_hashing.rb
1 2 module ActiveRecordHashing 3 def to_hash 4 Hash[*self.map{ |m| [m.id, m]}.flatten] 5 end 6 end
and in config/environment.rb
1 2 require 'ar_hashing' 3 4 class ActiveRecord::Associations::AssociationCollection 5 include ActiveRecordHashing 6 end