Last active
August 26, 2016 20:03
-
-
Save Chryus/7ef43957a66588daca35e54a72061df6 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| | |
json.(self, :incident_address, :borough, :latitude, :longitude) | |
json.upvotes(self.upvotes.count) | |
json.upvoted_by(self.upvotes.pluck(:user_id)) | |
end | |
end | |
# Customizing as_json with plain old ruby | |
def as_json(options={}) | |
g = super(:only => [:incident_address, :borough, :latitude, :longitude]) | |
g[:upvotes] = upvotes.count | |
g[:voted_by] = upvotes.pluck(:user_id) | |
g | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment