-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement jbuilder for comments controller.
- Loading branch information
Showing
7 changed files
with
36 additions
and
9 deletions.
There are no files selected for viewing
Binary file not shown.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Common | ||
def set_vars(allowed = {}) | ||
@question_id = allowed[:question_id] | ||
@answer_id = allowed[:answer_id] | ||
@comment_id = allowed[:comment_id] | ||
@id = allowed[:id] | ||
@content = allowed[:content] | ||
@user_id = current_user.id if current_user | ||
end | ||
|
||
def action_on_question | ||
question_id && answer_id.nil? | ||
end | ||
|
||
def action_on_answer | ||
answer_id && question_id.nil? | ||
end | ||
|
||
def action_on_comment | ||
comment_id.present? | ||
end | ||
|
||
def error_response(message = false, status = 403) | ||
render json: { error: message }, status: status | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
json.comments comments, partial: 'comments/default', as: :data | ||
json.comments @comment, partial: 'comments/default', as: :data |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
json.array!(@comments) do |comment| | ||
json.extract! comment, :id | ||
json.url comment_url(comment, format: :json) | ||
json.array!(@resource_comments) do |comment| | ||
json.partial! 'comments/default', data: comment | ||
json.extract! comment, :comment_on_id, :comment_on_type | ||
json.partial! 'users/user', user: comment.user | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
json.extract! @comment, :id, :created_at, :updated_at | ||
json.partial! 'comments/default', data: @comment | ||
json.extract! @comment, :comment_on_id, :comment_on_type | ||
json.partial! 'users/user', user: @comment.user |