Skip to content

Instantly share code, notes, and snippets.

@tiomoreno
Last active August 29, 2015 14:24
Show Gist options
  • Save tiomoreno/fd5904491d98670c7173 to your computer and use it in GitHub Desktop.
Save tiomoreno/fd5904491d98670c7173 to your computer and use it in GitHub Desktop.
active record extension
module ActiveRecordExtension
extend ActiveSupport::Concern
def as_json(options = {})
begin
serializer_class = "#{self.class}Serializer"
serializer_class.constantize.new(self, {root: false})
rescue LoadError => e
super(options)
end
end
end
ActiveRecord::Base.send(:include, ActiveRecordExtension)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment