Refactoring comments_controller#create reducing lines (#9162)
This commit is contained in:
parent
879e0ae1c8
commit
b5de27f1a6
2 changed files with 20 additions and 20 deletions
|
|
@ -77,26 +77,8 @@ class CommentsController < ApplicationController
|
|||
return
|
||||
end
|
||||
|
||||
render json: {
|
||||
status: "created",
|
||||
css: @comment.custom_css,
|
||||
depth: @comment.depth,
|
||||
url: @comment.path,
|
||||
readable_publish_date: @comment.readable_publish_date,
|
||||
published_timestamp: @comment.decorate.published_timestamp,
|
||||
body_html: @comment.processed_html,
|
||||
id: @comment.id,
|
||||
id_code: @comment.id_code_generated,
|
||||
newly_created: true,
|
||||
user: {
|
||||
id: current_user.id,
|
||||
username: current_user.username,
|
||||
name: current_user.name,
|
||||
profile_pic: ProfileImage.new(current_user).get(width: 50),
|
||||
twitter_username: current_user.twitter_username,
|
||||
github_username: current_user.github_username
|
||||
}
|
||||
}
|
||||
render partial: "comments/comment.json"
|
||||
|
||||
elsif (comment = Comment.where(
|
||||
body_markdown: @comment.body_markdown,
|
||||
commentable_id: @comment.commentable.id,
|
||||
|
|
|
|||
18
app/views/comments/_comment.json.jbuilder
Normal file
18
app/views/comments/_comment.json.jbuilder
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
json.status "created"
|
||||
json.css @comment.custom_css
|
||||
json.depth @comment.depth
|
||||
json.url @comment.path
|
||||
json.readable_publish_date @comment.readable_publish_date
|
||||
json.published_timestamp @comment.decorate.published_timestamp
|
||||
json.body_html @comment.processed_html
|
||||
json.id @comment.id
|
||||
json.id_code @comment.id_code_generated
|
||||
json.newly_created true
|
||||
json.user do
|
||||
json.id current_user.id
|
||||
json.username current_user.username
|
||||
json.name current_user.name
|
||||
json.profile_pic ProfileImage.new(current_user).get(width: 50)
|
||||
json.twitter_username current_user.twitter_username
|
||||
json.github_username current_user.github_username
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue