Skip to content

Instantly share code, notes, and snippets.

@rails-hub
Created May 18, 2015 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rails-hub/14cf84ab19bd428a6cd8 to your computer and use it in GitHub Desktop.
Save rails-hub/14cf84ab19bd428a6cd8 to your computer and use it in GitHub Desktop.
class ToolPresenter < SimpleDelegator
require 'rubygems'
require 'action_view'
include ActionView::Helpers::DateHelper
def initialize(posts)
@posts = posts
end
def comments
user_posts = []
@posts.each do |post|
post_comments = []
post.replies.order("created_at DESC").each do |comment|
reply = OpenStruct.new(:id => comment.id,:user => comment.user, :name => comment.user.decorate.name, :anonymous_label => comment.user.decorate.anonymous_label ,:avatar_url => comment.user.decorate.avatar_url, :comment_text => comment.text, :created_at => time_ago_in_words(comment.created_at))
post_comments << reply
end
all_comment = OpenStruct.new(:id => post.id, :user => post.user, :name => post.user.decorate.name, :anonymous_label => post.user.decorate.anonymous_label, :avatar_url => post.user.decorate.avatar_url, :comment_text => post.text, :created_at => time_ago_in_words(post.created_at), :replies => post_comments)
user_posts << all_comment
end
user_posts
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment