Skip to content

Instantly share code, notes, and snippets.

@andrei512
Created September 20, 2012 14:12
Show Gist options
  • Save andrei512/3756183 to your computer and use it in GitHub Desktop.
Save andrei512/3756183 to your computer and use it in GitHub Desktop.
comments
def reactions
@article = Article.find(params[:article_id])
comments = @article.comments.includes(:user)
emotions = @article.emotions.includes(:user)
reactions = comments + emotions
reactions.sort! { |x, y|
y.created_at <=> x.created_at
}
render json: reactions
end
[{
"emotion": ":)",
"user_id": 1,
"user": {
"id": 1,
"name": "user10713417811",
"tiny_avatar": "/avatars/tiny/missing.png",
"normal_avatar": "/avatars/normal/missing.png"
}
}, {
"comment": "ia pula!",
"created_at": "2012-09-20T02:14:06Z",
"id": 1,
"user": {
"id": 1,
"name": "user10713417811",
"tiny_avatar": "/avatars/tiny/missing.png",
"normal_avatar": "/avatars/normal/missing.png"
}
}, {
"comment": "ia pula!",
"created_at": "2012-09-20T02:14:19Z",
"id": 2,
"user": {
"id": 1,
"name": "user10713417811",
"tiny_avatar": "/avatars/tiny/missing.png",
"normal_avatar": "/avatars/normal/missing.png"
}
}, {
"comment": "ia pula!",
"created_at": "2012-09-20T02:14:20Z",
"id": 3,
"user": {
"id": 1,
"name": "user10713417811",
"tiny_avatar": "/avatars/tiny/missing.png",
"normal_avatar": "/avatars/normal/missing.png"
}
}, {
"comment": "ia pula!",
"created_at": "2012-09-20T02:14:20Z",
"id": 4,
"user": {
"id": 1,
"name": "user10713417811",
"tiny_avatar": "/avatars/tiny/missing.png",
"normal_avatar": "/avatars/normal/missing.png"
}
}, {
"comment": "ia pula!",
"created_at": "2012-09-20T02:14:20Z",
"id": 5,
"user": {
"id": 1,
"name": "user10713417811",
"tiny_avatar": "/avatars/tiny/missing.png",
"normal_avatar": "/avatars/normal/missing.png"
}
}, {
"comment": "ia pula!",
"created_at": "2012-09-20T02:14:20Z",
"id": 6,
"user": {
"id": 1,
"name": "user10713417811",
"tiny_avatar": "/avatars/tiny/missing.png",
"normal_avatar": "/avatars/normal/missing.png"
}
}, {
"comment": "ia pula din nou!",
"created_at": "2012-09-20T02:15:37Z",
"id": 8,
"user": {
"id": 1,
"name": "user10713417811",
"tiny_avatar": "/avatars/tiny/missing.png",
"normal_avatar": "/avatars/normal/missing.png"
}
}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment