aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/file_request_controller.rb18
-rw-r--r--app/models/info_request.rb3
-rw-r--r--app/models/outgoing_message.rb23
-rw-r--r--app/views/file_request/index.rhtml2
4 files changed, 36 insertions, 10 deletions
diff --git a/app/controllers/file_request_controller.rb b/app/controllers/file_request_controller.rb
index f062f0da8..8424c83b0 100644
--- a/app/controllers/file_request_controller.rb
+++ b/app/controllers/file_request_controller.rb
@@ -4,26 +4,28 @@
# 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.4 2007-09-10 01:16:35 francis Exp $
+# $Id: file_request_controller.rb,v 1.5 2007-09-10 18:58:43 francis Exp $
class FileRequestController < ApplicationController
def index
end
def create
-# raise params[:info_request][:public_body_id]
-# params[:info_request][:public_body] = PublicBody.find(params[:info_request][:public_body_id])
-# params[:info_request].delete(:public_body_id)
@info_request = InfoRequest.new(params[:info_request])
+ @outgoing_message = OutgoingMessage.new(params[:outgoing_message].merge({ :status => 'ready',
+ :message_type => 'initial_request'}))
- if not @info_request.save
- render :action => 'index'
- else
+ InfoRequest.transaction do
+ @info_request.save!
+ @outgoing_message.info_request_id = @info_request.id
+ @outgoing_message.save!
# render create action
end
+ rescue ActiveRecord::RecordInvalid => e
+ @outgoing_message.valid? # force cecking of errors even if info_request fails
+ render :action => 'index'
end
-
end
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 21f9e47cb..c354fb3af 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -4,11 +4,12 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: info_request.rb,v 1.3 2007-09-10 01:16:35 francis Exp $
+# $Id: info_request.rb,v 1.4 2007-09-10 18:58:43 francis Exp $
class InfoRequest < ActiveRecord::Base
belongs_to :user
belongs_to :public_body
+ has_many :outgoing_message
# validates_presence_of :user
# validates_numericality_of :user
diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb
new file mode 100644
index 000000000..186bb2147
--- /dev/null
+++ b/app/models/outgoing_message.rb
@@ -0,0 +1,23 @@
+# models/outgoing_message.rb:
+# A message, associated with a request, from the user of the site to somebody
+# else. e.g. An initial request for information, or a complaint.
+#
+# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
+# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
+#
+# $Id: outgoing_message.rb,v 1.1 2007-09-10 18:58:43 francis Exp $
+
+class OutgoingMessage < ActiveRecord::Base
+ belongs_to :info_request
+ validates_presence_of :info_request_id
+
+ validates_presence_of :body
+ validates_inclusion_of :status, :in => ['ready', 'sent', 'failed']
+
+ belongs_to :public_body
+ validates_inclusion_of :message_type, :in => ['initial_request'] #, 'complaint']
+
+ belongs_to :recipient, :polymorphic => true
+
+end
+
diff --git a/app/views/file_request/index.rhtml b/app/views/file_request/index.rhtml
index 8e4955463..84d0198bc 100644
--- a/app/views/file_request/index.rhtml
+++ b/app/views/file_request/index.rhtml
@@ -1,6 +1,6 @@
<% @title = "New FOI request" %>
-<%= foi_error_messages_for :info_request %>
+<%= foi_error_messages_for :info_request, :outgoing_message %>
<% form_for(:info_request, @info_request, :url => { :action => :create }, :html => { :id => 'writeForm' } ) do |f| %>