diff options
Diffstat (limited to 'app/models/contact_validator.rb')
-rw-r--r-- | app/models/contact_validator.rb | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/app/models/contact_validator.rb b/app/models/contact_validator.rb index d277161f9..65e539669 100644 --- a/app/models/contact_validator.rb +++ b/app/models/contact_validator.rb @@ -1,35 +1,29 @@ -# == Schema Information -# Schema version: 114 -# -# Table name: contact_validators -# -# name :string -# email :string -# subject :text -# message :text -# - # models/contact_validator.rb: # Validates contact form submissions. # # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. -# Email: francis@mysociety.org; WWW: http://www.mysociety.org/ +# Email: hello@mysociety.org; WWW: http://www.mysociety.org/ -class ContactValidator < ActiveRecord::BaseWithoutTable - strip_attributes! +class ContactValidator + include ActiveModel::Validations - column :name, :string - column :email, :string - column :subject, :text - column :message, :text + attr_accessor :name, :email, :subject, :message validates_presence_of :name, :message => N_("Please enter your name") validates_presence_of :email, :message => N_("Please enter your email address") validates_presence_of :subject, :message => N_("Please enter a subject") validates_presence_of :message, :message => N_("Please enter the message you want to send") + validate :email_format - def validate - errors.add(:email, _("Email doesn't look like a valid address")) unless MySociety::Validate.is_valid_email(self.email) + def initialize(attributes = {}) + attributes.each do |name, value| + send("#{name}=", value) + end end + private + + def email_format + errors.add(:email, _("Email doesn't look like a valid address")) unless MySociety::Validate.is_valid_email(self.email) + end end |