aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorfrancis <francis>2007-09-11 15:21:16 +0000
committerfrancis <francis>2007-09-11 15:21:16 +0000
commit8da18792e68c71410e8c6ba31c8eb24bf13a407f (patch)
tree02e151396ab7376316d8f34b22b3f17810c1c397 /app
parentffe3932a317dd81a73ec0c930651bf8447eebcc8 (diff)
Tidy up the transaction.
Diffstat (limited to 'app')
-rw-r--r--app/controllers/file_request_controller.rb29
1 files changed, 18 insertions, 11 deletions
diff --git a/app/controllers/file_request_controller.rb b/app/controllers/file_request_controller.rb
index 8424c83b0..b87fc4a9e 100644
--- a/app/controllers/file_request_controller.rb
+++ b/app/controllers/file_request_controller.rb
@@ -4,26 +4,33 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: file_request_controller.rb,v 1.5 2007-09-10 18:58:43 francis Exp $
+# $Id: file_request_controller.rb,v 1.6 2007-09-11 15:21:16 francis Exp $
class FileRequestController < ApplicationController
def index
end
def create
+ # Create both FOI request and the first request message
@info_request = InfoRequest.new(params[:info_request])
- @outgoing_message = OutgoingMessage.new(params[:outgoing_message].merge({ :status => 'ready',
- :message_type => 'initial_request'}))
+ @outgoing_message = OutgoingMessage.new(params[:outgoing_message].merge({
+ :status => 'ready',
+ :message_type => 'initial_request'
+ }))
- InfoRequest.transaction do
- @info_request.save!
- @outgoing_message.info_request_id = @info_request.id
- @outgoing_message.save!
- # render create action
+ # Save both models
+ ActiveRecord::Base.transaction do
+ begin
+ @info_request.save!
+ @outgoing_message.info_request_id = @info_request.id
+ @outgoing_message.save!
+ # render create action
+ rescue ActiveRecord::RecordInvalid => e
+ @outgoing_message.valid? # force cecking of errors even if info_request fails
+ @outgoing_message.errors.full_messages.delete("info_request")
+ render :action => 'index'
+ end
end
- rescue ActiveRecord::RecordInvalid => e
- @outgoing_message.valid? # force cecking of errors even if info_request fails
- render :action => 'index'
end
end