From 0541cc4a14da751d744dcfd132ee4bbef0db4266 Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Sun, 7 Oct 2012 12:55:35 -0300 Subject: [PATCH] Searching comments on page before editing it --- app/controllers/public/content_viewer_controller.rb | 29 +++++++++++++++++++---------- app/views/content_viewer/_comment_form.rhtml | 20 +++++++++++--------- plugins/tolerance_time/lib/tolerance_time_plugin.rb | 4 ++-- plugins/tolerance_time/lib/tolerance_time_plugin/publication.rb | 2 +- test/functional/content_viewer_controller_test.rb | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 22 deletions(-) diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index 7dce933..92c90aa 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -127,15 +127,20 @@ class ContentViewerController < ApplicationController path = params[:page].join('/') @page = profile.articles.find_by_path(path) @form_div = 'opened' - @comment = Comment.find(params[:id]) - if request.post? - begin - @comment.update_attributes(params[:comment]) - session[:notice] = _('Comment updated.') - redirect_to :action => 'view_page', :profile => profile.identifier, :page => @comment.article.explode_path - rescue - session[:notice] = _('Comment could not be updated.') + @comment = @page.comments.find_by_id(params[:id]) + if @comment + if request.post? + begin + @comment.update_attributes(params[:comment]) + session[:notice] = _('Comment succesfully updated') + redirect_to :action => 'view_page', :profile => profile.identifier, :page => @comment.article.explode_path + rescue + session[:notice] = _('Comment could not be updated') + end end + else + redirect_to @page.view_url + session[:notice] = _('Could not find the comment in the article') end end @@ -217,8 +222,12 @@ class ContentViewerController < ApplicationController end def comment_author - comment = Comment.find(params[:id]) - render_access_denied if comment.author.blank? || comment.author != user + comment = Comment.find_by_id(params[:id]) + if comment + render_access_denied if comment.author.blank? || comment.author != user + else + render_not_found + end end end diff --git a/app/views/content_viewer/_comment_form.rhtml b/app/views/content_viewer/_comment_form.rhtml index 2bc4e36..c19a877 100644 --- a/app/views/content_viewer/_comment_form.rhtml +++ b/app/views/content_viewer/_comment_form.rhtml @@ -32,15 +32,17 @@ function submit_comment_form(button) {
-

- <%= content_tag('a', '', :name => 'comment_form') + _('Post a comment') if display_link %> -

+<% if display_link %> +

+ <%= content_tag('a', '', :name => 'comment_form') + _('Post a comment') %> +

+<% end %> <% unless pass_without_comment_captcha? %>