Skip to content

Instantly share code, notes, and snippets.

@fidalgo
Created February 15, 2018 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fidalgo/847c2596047f6f4c5e8c947a91369072 to your computer and use it in GitHub Desktop.
Save fidalgo/847c2596047f6f4c5e8c947a91369072 to your computer and use it in GitHub Desktop.
Rails JSON serialize
include ActiveModel::Serializers::JSON
def attributes
result = {}
object_methods = self.class.instance_methods(false) - self.class.public_methods(false)
object_methods.each do |method|
result[method] = send(method)
end
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment