From a2b034ea36cce031cc88528c7b5b31b5fc5bdf51 Mon Sep 17 00:00:00 2001 From: joshua stein Date: Wed, 10 Oct 2012 17:29:02 -0500 Subject: [PATCH] fix pulling vote for current story when showing a specific comment --- app/controllers/stories_controller.rb | 45 +++++++++++---------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index b012c15..b9e7e2f 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -117,19 +117,7 @@ class StoriesController < ApplicationController @user ? @user : nil) @comment = Comment.new - if @user - if v = Vote.find_by_user_id_and_story_id_and_comment_id(@user.id, - @story.id, nil) - @story.vote = v.vote - end - - @votes = Vote.comment_votes_by_user_for_story_hash(@user.id, @story.id) - @comments.each do |c| - if @votes[c.id] - c.current_vote = @votes[c.id] - end - end - end + load_user_votes end def show_comment @@ -155,19 +143,8 @@ class StoriesController < ApplicationController end @comment = Comment.new - - if @user - if v = Vote.find_by_user_id_and_story_id(@user.id, @story.id) - @story.vote = v.vote - end - - @votes = Vote.comment_votes_by_user_for_story_hash(@user.id, @story.id) - @comments.each do |c| - if @votes[c.id] - c.current_vote = @votes[c.id] - end - end - end + + load_user_votes render :action => "show" end @@ -255,4 +232,20 @@ private return false end end + + def load_user_votes + if @user + if v = Vote.find_by_user_id_and_story_id_and_comment_id(@user.id, + @story.id, nil) + @story.vote = v.vote + end + + @votes = Vote.comment_votes_by_user_for_story_hash(@user.id, @story.id) + @comments.each do |c| + if @votes[c.id] + c.current_vote = @votes[c.id] + end + end + end + end end