Created
February 15, 2018 15:01
-
-
Save fidalgo/847c2596047f6f4c5e8c947a91369072 to your computer and use it in GitHub Desktop.
Rails JSON serialize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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