diff options
author | francis <francis> | 2007-11-09 02:11:35 +0000 |
---|---|---|
committer | francis <francis> | 2007-11-09 02:11:35 +0000 |
commit | dc965b43e5784d6dde2f06186cb14c4640da65a4 (patch) | |
tree | 3cc74426cae3ae1d96f7dbb2ec5791b0b2a31c2e /app/models | |
parent | ccbb11e060b6c1972054f29377ac435375a3ddf5 (diff) |
Have default text for letter.
Prevent sending of letter if unaltered.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/outgoing_message.rb | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb index dc8541ba8..e944c5b87 100644 --- a/app/models/outgoing_message.rb +++ b/app/models/outgoing_message.rb @@ -5,7 +5,7 @@ # 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.9 2007-11-07 11:10:56 francis Exp $ +# $Id: outgoing_message.rb,v 1.10 2007-11-09 02:11:36 francis Exp $ class OutgoingMessage < ActiveRecord::Base belongs_to :info_request @@ -16,6 +16,23 @@ class OutgoingMessage < ActiveRecord::Base validates_inclusion_of :message_type, :in => ['initial_request'] #, 'complaint'] + # Set default letter + def after_initialize + if self.body.nil? + self.body = "Dear Sir or Madam,\n\n\n\nYours faithfully,\n\n" + end + end + + # Check have edited letter + def validate + if self.body =~ /\ADear Sir or Madam,\s+Yours faithfully,\s+/ + errors.add(:body, "^Please enter your letter requesting information") + end + if self.body =~ /Yours faithfully,\s+\Z/ + errors.add(:body, '^Please sign at the bottom with your name, or alter the "Yours faithfully" signature') + end + end + # Deliver outgoing message # Note: You can test this from script/console with, say: # InfoRequest.find(1).outgoing_messages[0].send_message |