aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfrancis <francis>2007-09-17 10:13:24 +0000
committerfrancis <francis>2007-09-17 10:13:24 +0000
commit709d4d01ae6adfae49c0d7376faec112a8d7d0ee (patch)
tree8836c0c4949964e3c99c2db115954d39a74b11f5
parent10f9dd9a5d20017be3cd58778a451cc28458f437 (diff)
Try to use implicit saving of dependent models, rather than explicit.
Still has some problems in error display :(
-rw-r--r--app/controllers/file_request_controller.rb27
-rw-r--r--app/models/info_request.rb4
-rw-r--r--app/models/public_body.rb4
-rw-r--r--app/models/user.rb4
-rw-r--r--todo.txt2
5 files changed, 25 insertions, 16 deletions
diff --git a/app/controllers/file_request_controller.rb b/app/controllers/file_request_controller.rb
index ab9390a4f..2f2ae9b58 100644
--- a/app/controllers/file_request_controller.rb
+++ b/app/controllers/file_request_controller.rb
@@ -4,33 +4,40 @@
# 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.8 2007-09-12 15:56:18 francis Exp $
+# $Id: file_request_controller.rb,v 1.9 2007-09-17 10:13:24 francis Exp $
class FileRequestController < ApplicationController
def index
# render index.rhtml template
end
-# before_filter :check_authentication, :only => [:create]
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'
}))
+ @info_request.outgoing_messages << @outgoing_message
@outgoing_message.info_request = @info_request
- # Save both models
- valid = @info_request.valid?
- valid &&= @outgoing_message.valid? # XXX maybe there is a nicer way of preventing lazy boolean evaluation than this
- if valid
- @info_request.save!
- @outgoing_message.save!
- else
+ # This automatically saves dependent objects, such as @info_request, in the same transaction
+ if not @info_request.save
+ raise @info_request.errors.@errors.to_yaml
render :action => 'index'
end
+
+ # Save both models
+# valid = @info_request.valid?
+# valid &&= @outgoing_message.valid? # XXX maybe there is a nicer way of preventing lazy boolean evaluation than this
+# if valid
+# if check_authentication
+# @info_request.save!
+# @outgoing_message.save!
+# end
+# else
+# render :action => 'index'
+# end
end
end
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 101773a30..248f9423e 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -4,7 +4,7 @@
# 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.5 2007-09-11 15:23:59 francis Exp $
+# $Id: info_request.rb,v 1.6 2007-09-17 10:13:24 francis Exp $
class InfoRequest < ActiveRecord::Base
validates_presence_of :title
@@ -15,6 +15,6 @@ class InfoRequest < ActiveRecord::Base
belongs_to :public_body
validates_presence_of :public_body_id
- has_many :outgoing_message
+ has_many :outgoing_messages
end
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index c2c270e6b..9e660f413 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -4,12 +4,12 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: public_body.rb,v 1.5 2007-09-10 01:16:35 francis Exp $
+# $Id: public_body.rb,v 1.6 2007-09-17 10:13:24 francis Exp $
class PublicBody < ActiveRecord::Base
validates_presence_of :request_email
- has_many :info_request
+ has_many :info_requests
def validate
unless MySociety::Validate.is_valid_email(request_email)
diff --git a/app/models/user.rb b/app/models/user.rb
index 97f781151..781482dcf 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -4,7 +4,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: user.rb,v 1.6 2007-09-12 08:52:23 francis Exp $
+# $Id: user.rb,v 1.7 2007-09-17 10:13:24 francis Exp $
require 'digest/sha1'
@@ -14,7 +14,7 @@ class User < ActiveRecord::Base
validates_presence_of :name
- has_many :info_request
+ has_many :info_requests
attr_accessor :password_confirmation
validates_confirmation_of :password
diff --git a/todo.txt b/todo.txt
index cee978a32..a577b04ba 100644
--- a/todo.txt
+++ b/todo.txt
@@ -8,6 +8,8 @@ Write some tests (try it their way, at every level)
Tidying
=======
+Prevent double posting of same request
+
If summary is blank, says "title must be filled in" grrrr
Tidy up error message text (like "body must be filled in") on info request form