adding likes, reshares and comments in a naive presenter way

This commit is contained in:
Maxwell Salzberg 2012-02-21 22:13:46 -08:00
parent 7755c254fb
commit cd274cad0d

View file

@ -19,12 +19,27 @@ class PostPresenter
:reshares_count => self.post.reshares.count,
:user_reshare => self.user_reshare,
:next_post => self.next_post_path,
:previous_post => self.previous_post_path
:previous_post => self.previous_post_path,
:likes => self.likes,
:reshares => self.reshares,
:comments => self.comments
}),
:templateName => template_name
}
end
def comments
as_api(post.comments)
end
def likes
as_api(post.likes)
end
def reshares
as_api(post.reshares)
end
def user_like
return unless user_signed_in?
if like = post.likes.where(:author_id => person.id).first
@ -70,6 +85,12 @@ class PostPresenter
protected
def as_api(collection)
collection.includes(:author => :profile).all.map do |element|
element.as_api_response(:backbone)
end
end
def post_base
if current_user
current_user.posts_from(self.post.author)