Created
September 20, 2012 14:12
-
-
Save andrei512/3756183 to your computer and use it in GitHub Desktop.
comments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{ | |
"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