2016-12-22 20:05:38 +08:00
|
|
|
module CommentsHelper
|
|
|
|
def get_micropost_comments micropost_id
|
|
|
|
comments_array = Array.new()
|
|
|
|
micropost = MicroPost.find_by(id: micropost_id)
|
2016-12-22 23:23:22 +08:00
|
|
|
comments = micropost.comments.order(comment_time: :desc)
|
2016-12-22 20:05:38 +08:00
|
|
|
if !comments.empty?
|
|
|
|
comments.each do |com|
|
|
|
|
temp = Hash.new()
|
|
|
|
temp["username"] = com.user.name
|
|
|
|
temp["userpic"] = com.user.picurl
|
|
|
|
temp["content"] = com.content
|
|
|
|
comments_array << temp
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return comments_array
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|