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 | |
parent | ccbb11e060b6c1972054f29377ac435375a3ddf5 (diff) |
Have default text for letter.
Prevent sending of letter if unaltered.
-rw-r--r-- | app/controllers/request_controller.rb | 3 | ||||
-rw-r--r-- | app/models/outgoing_message.rb | 19 | ||||
-rw-r--r-- | todo.txt | 4 |
3 files changed, 22 insertions, 4 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 58ecd3478..347838827 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.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: request_controller.rb,v 1.13 2007-11-06 15:58:56 francis Exp $ +# $Id: request_controller.rb,v 1.14 2007-11-09 02:11:35 francis Exp $ class RequestController < ApplicationController @@ -25,6 +25,7 @@ class RequestController < ApplicationController def new # Read parameters in - public body can be passed from front page @info_request = InfoRequest.new(params[:info_request]) + @outgoing_message = OutgoingMessage.new(params[:outgoing_message]) end # Page new form posts to 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 @@ -11,13 +11,13 @@ Email has already been taken hasn't got a link to better place Link from error page for signin/signup to go to other one Remember me box -Make it say "dear" as default letter - Work out how to get it to tell you code coverage of .rhtml files Make it validate the HTML maybe with http://www.anodyne.ca/wp-content/uploads/2007/09/be_valid_xhtml.rb Check we call integrate_views for all controllers +Remove "Outgoing messages is invalid" + Tidying ======= |