You probably need to call all too. Itβs just that to_a will work fine in a scope or an existing result set (e.g. User.active.to_hash ), but not directly on the model (e.g. User.to_hash ). Using all.to_a will work for both scenarios.
def self.to_hash all.to_a.map(&:serializable_hash) end
Note that all.to_a is a little duplicate, since all already returns an array, but in Rails 4 it will be necessary.
source share