From c45a888e1ea1e74e12d4837e3bf20c4e81ed32f9 Mon Sep 17 00:00:00 2001 From: jomo Date: Sun, 8 Feb 2015 00:32:00 +0100 Subject: [PATCH] redirect to correct blogpost page --- app/controllers/comments_controller.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 9a874b5..be0783e 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -19,7 +19,9 @@ class CommentsController < ApplicationController if @comment.save @comment.send_new_comment_mail @comment.send_new_mention_mail - redirect_to blogpost_path(@comment.blogpost) + "#comment-#{@comment.id}", notice: 'Comment created!' + position = @comment.blogpost.comments.count - 1 + page = position / Kaminari.config.default_per_page + 1 + redirect_to blogpost_path(@comment.blogpost, page: page) + "#comment-#{@comment.id}", notice: 'Comment created!' else flash[:alert] = "Could not create comment." redirect_to Blogpost.find(params[:blogpost_id]) @@ -39,7 +41,9 @@ class CommentsController < ApplicationController if @comment.save @comment.send_new_mention_mail(old_content) flash[:notice] = "Comment updated!" - redirect_to blogpost_path(@comment.blogpost) + "#comment-#{@comment.id}" + position = @comment.blogpost.comments.index(@comment) + page = position / Kaminari.config.default_per_page + 1 + redirect_to blogpost_path(@comment.blogpost, page: page) + "#comment-#{@comment.id}" else flash[:alert] = "There was a problem while updating your comment" render action: "edit"