aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2014-03-11 14:32:19 +0000
committerGareth Rees <gareth@mysociety.org>2014-03-13 11:48:42 +0000
commit10fbde73f2782df0f007c668d07c8067b2fbb4dc (patch)
tree4979daae936de6f964da8e7fa629ed3fd61599df
parent550ed0aa483d0b31a6f844a728340e5a81a753ed (diff)
Extract find_info_request from CommentController
Use a before_filter to make @info_request available to all filters called on the same action
-rw-r--r--app/controllers/comment_controller.rb29
1 files changed, 17 insertions, 12 deletions
diff --git a/app/controllers/comment_controller.rb b/app/controllers/comment_controller.rb
index 4904463b5..c2315b73e 100644
--- a/app/controllers/comment_controller.rb
+++ b/app/controllers/comment_controller.rb
@@ -6,20 +6,16 @@
class CommentController < ApplicationController
before_filter :check_read_only, :only => [ :new ]
+ before_filter :find_info_request, :only => [ :new ]
protect_from_forgery :only => [ :new ]
def new
- if params[:type] == 'request'
- @info_request = InfoRequest.find_by_url_title!(params[:url_title])
- @track_thing = TrackThing.create_track_for_request(@info_request)
- if params[:comment]
- @comment = Comment.new(params[:comment].merge({
- :comment_type => 'request',
- :user => @user
- }))
- end
- else
- raise "Unknown type " + params[:type]
+ @track_thing = TrackThing.create_track_for_request(@info_request)
+ if params[:comment]
+ @comment = Comment.new(params[:comment].merge({
+ :comment_type => 'request',
+ :user => @user
+ }))
end
# Are comments disabled on this request?
@@ -94,5 +90,14 @@ class CommentController < ApplicationController
end
end
-end
+ private
+ def find_info_request
+ if params[:type] == 'request'
+ @info_request = InfoRequest.find_by_url_title!(params[:url_title])
+ else
+ raise "Unknown type #{ params[:type] }"
+ end
+ end
+
+end