Add gravatar picture to comments

This commit is contained in:
riggraz
2019-09-30 23:28:52 +02:00
parent 4fdb71d488
commit be8f003d70
6 changed files with 25 additions and 3 deletions

View File

@@ -3,9 +3,16 @@ class CommentsController < ApplicationController
def index
comments = Comment
.select(
:id,
:body,
:parent_id,
:updated_at,
'users.full_name as user_full_name',
'users.email as user_email',
)
.where(post_id: params[:post_id])
.left_outer_joins(:user)
.select('comments.id, comments.body, comments.parent_id, comments.updated_at, users.full_name as user_full_name')
.order(updated_at: :desc)
render json: comments
@@ -15,8 +22,9 @@ class CommentsController < ApplicationController
comment = Comment.new(comment_params)
if comment.save
render json: comment.attributes.merge({ user_full_name: current_user.full_name}),
status: :created
render json: comment.attributes.merge(
{ user_full_name: current_user.full_name, user_email: current_user.email}
), status: :created
else
render json: {
error: I18n.t('errors.comment.create', message: comment.errors.full_messages)