summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMrYummy <elemental428@gmail.com>2017-06-21 01:59:02 +0200
committerMrYummy <elemental428@gmail.com>2017-06-21 01:59:02 +0200
commit3bfc74045fa61e7646754a1563c8813ed0952f14 (patch)
tree90586a7da1f2a7ff03d5126b93e47161fd077309
parent992406a20b90d47d1ef8a9b4f8d0c599590a1171 (diff)
hi
-rw-r--r--app/controllers/blogposts_controller.rb18
-rw-r--r--app/controllers/comments_controller.rb8
-rw-r--r--app/controllers/users_controller.rb4
3 files changed, 25 insertions, 5 deletions
diff --git a/app/controllers/blogposts_controller.rb b/app/controllers/blogposts_controller.rb
index 79c9e5d..903b262 100644
--- a/app/controllers/blogposts_controller.rb
+++ b/app/controllers/blogposts_controller.rb
@@ -8,8 +8,16 @@ class BlogpostsController < ApplicationController
end
def show
- @comment = Comment.new(blogpost: @post)
- @comments = @post.comments.page(params[:page])
+ if @post
+ @comment = Comment.new(blogpost: @post)
+ @comments = @post.comments.page(params[:page])
+ respond_to do |format|
+ format.html
+ format.json {render json: @post.attributes.merge(replies: Comment.where(blogpost: @post).ids).to_json}
+ end
+ else
+ respond_to {|format| format.json {render json: Comment.find_by(id: params[:id][1..-1]).try(:attributes).to_json}}
+ end
end
def new
@@ -64,7 +72,9 @@ class BlogpostsController < ApplicationController
def set_post
if params[:id]
- @post = Blogpost.find(params[:id])
+ unless action_name == "show" && params[:id][0].downcase == "c"
+ @post = Blogpost.find(params[:id])
+ end
end
end
@@ -75,4 +85,4 @@ class BlogpostsController < ApplicationController
end
end
-end \ No newline at end of file
+end
diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb
index 3c2f57d..78821e5 100644
--- a/app/controllers/comments_controller.rb
+++ b/app/controllers/comments_controller.rb
@@ -2,6 +2,12 @@ class CommentsController < ApplicationController
include MailerHelper
+ def show
+ respond_to do |format|
+ format.json {render json: @comment.attributes.to_json}
+ end
+ end
+
def edit
@comment = Comment.find(params[:id])
if mod? || @comment.author.is?(current_user)
@@ -72,4 +78,4 @@ class CommentsController < ApplicationController
def comment_params
params.require(:comment).permit(:content)
end
-end \ No newline at end of file
+end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 5dc0e80..64aa2b7 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -30,6 +30,10 @@ class UsersController < ApplicationController
end
def show
+ respond_to do |format|
+ format.html
+ format.json {render json: @user.attributes.slice("id", "uuid", "ign", "name", "about", "donor", "confirmed", "last_seen", "created_at").to_json}
+ end
end
# SIGNUP