From dcfa7fd733008cd4b0bf066729df4b232342c65b Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 4 Nov 2014 14:52:49 +0000 Subject: RESTful routing for editing and updating comments --- app/controllers/admin_comment_controller.rb | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 app/controllers/admin_comment_controller.rb (limited to 'app/controllers/admin_comment_controller.rb') diff --git a/app/controllers/admin_comment_controller.rb b/app/controllers/admin_comment_controller.rb new file mode 100644 index 000000000..0aafb122a --- /dev/null +++ b/app/controllers/admin_comment_controller.rb @@ -0,0 +1,36 @@ +# app/controllers/admin_comment_controller.rb: +# Controller for editing comments from the admin interface. +# +# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. +# Email: hello@mysociety.org; WWW: http://www.mysociety.org/ + +class AdminCommentController < AdminController + + def edit + @comment = Comment.find(params[:id]) + end + + def update + @comment = Comment.find(params[:id]) + + old_body = @comment.body + old_visible = @comment.visible + @comment.visible = params[:comment][:visible] == "true" ? true : false + + if @comment.update_attributes(params[:comment]) + @comment.info_request.log_event("edit_comment", + { :comment_id => @comment.id, + :editor => admin_current_user(), + :old_body => old_body, + :body => @comment.body, + :old_visible => old_visible, + :visible => @comment.visible, + }) + flash[:notice] = 'Comment successfully updated.' + redirect_to admin_request_url(@comment.info_request) + else + render :action => 'edit' + end + end + +end -- cgit v1.2.3