From e6ce3a5d68982d56c5df92f657a8047e3167c906 Mon Sep 17 00:00:00 2001 From: joshua stein Date: Mon, 20 Jan 2014 23:30:46 -0600 Subject: [PATCH] show full story threads when highlighting a comment we're not paginating (yet) so just show the whole thread like normal and highlight the specific comment which gets scrolled to closes #107 --- app/controllers/stories_controller.rb | 41 ++++++--------------------- config/routes.rb | 2 +- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 2864893..079b915 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -127,6 +127,15 @@ class StoriesController < ApplicationController @comments = @story.comments.includes(:user).arrange_for_user(@user) + if params[:comment_short_id] + @comments.each do |c,x| + if c.short_id == params[:comment_short_id] + c.highlighted = true + break + end + end + end + respond_to do |format| format.html { @comment = @story.comments.build @@ -141,38 +150,6 @@ class StoriesController < ApplicationController end end - def show_comment - @story = Story.where(:short_id => params[:id]).first! - - @title = @story.title - - @showing_comment = Comment.where(:short_id => params[:comment_short_id]).first - - if !@showing_comment - flash[:error] = "Could not find comment. It may have been deleted." - return redirect_to @story.comments_url - end - - @comments = @story.comments - if @showing_comment.thread_id - @comments = @comments.where(:thread_id => @showing_comment.thread_id) - end - @comments = @comments.includes(:user).arrange_for_user(@user) - - @comments.each do |c,x| - if c.id == @showing_comment.id - c.highlighted = true - break - end - end - - @comment = @story.comments.build - - load_user_votes - - render :action => "show" - end - def undelete if !(@story.is_editable_by_user?(@user) && @story.is_undeletable_by_user?(@user)) diff --git a/config/routes.rb b/config/routes.rb index 6cc2d77..2a01ef6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -62,7 +62,7 @@ Lobsters::Application.routes.draw do post "keep_as_new" end - get "/s/:id/:title/comments/:comment_short_id" => "stories#show_comment" + get "/s/:id/:title/comments/:comment_short_id" => "stories#show" get "/s/:id/(:title)" => "stories#show" get "/u" => "users#tree"