Skip to content

Instantly share code, notes, and snippets.

@jraczak
Created November 28, 2012 22:01
Show Gist options
  • Select an option

  • Save jraczak/4164977 to your computer and use it in GitHub Desktop.

Select an option

Save jraczak/4164977 to your computer and use it in GitHub Desktop.
# abstracted code selection from tip.rb
# 'date_age' is named arbitrarily
def as_json(options = nil)
methods = []
methods << :can_upvote if @current_user_id.present?
methods << :date_age
super(methods: methods, include: { user: { only: :username } })
end
# calculate value to pass to JSON for availability in the partial
def date_age
time_ago_in_words(self.created_at)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment