guoren/app/helpers/comments_helper.rb

19 lines
496 B
Ruby
Raw Permalink Normal View History

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)
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