Created
August 10, 2010 22:38
-
-
Save aziz/518141 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ContactForm | |
@to = "Jason Seifer <[email protected]>" | |
include ActiveModel::AttributeMethods | |
include ActiveModel::Validations | |
include ActiveModel::Conversion | |
extend ActiveModel::Translation | |
extend ActiveModel::Callbacks | |
attr_accessor :name, :email, :message | |
validates_presence_of :name | |
validates_presence_of :email | |
validates_presence_of :message | |
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i | |
define_model_callbacks :save | |
def initialize(attributes={}) | |
attributes.each do |name, value| | |
send("#{name}=", value) | |
end | |
end | |
def read_attribute_for_validation(key) | |
send(key) | |
end | |
def to | |
self.class.instance_variable_get("@to") | |
end | |
def from | |
"#{name} <#{email}>" | |
end | |
def persisted? | |
false | |
end | |
def save | |
if valid? | |
Notifier.contact_form(self).deliver | |
else | |
return false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment