Last active
August 26, 2016 20:37
-
-
Save Chryus/3e1db6c6a76991ee7e6f9185785f8b12 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# customizing as_json with standalone JBuilder DSL | |
def as_json(options={}) | |
Jbuilder.encode do |json| | |
graffito = self | |
json.(graffito, :incident_address, :borough, :latitude, :longitude) | |
json.upvotes(graffito.upvotes.count) | |
json.upvoted_by(graffito.upvotes.pluck(:user_id)) | |
end | |
end | |
# Customizing as_json with plain old Rails | |
def as_json(options={}) | |
graffito = super(:only => [:incident_address, :borough, :latitude, :longitude]) | |
graffito[:upvotes] = upvotes.count | |
graffito[:voted_by] = upvotes.pluck(:user_id) | |
graffito | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment