Created
April 30, 2013 08:20
-
-
Save amardaxini/5487347 to your computer and use it in GitHub Desktop.
Contact Form in Rails without databse
This file contains 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 Contact | |
include ActiveModel::Validations | |
include ActiveModel::Serializers | |
include ActiveModel::MassAssignmentSecurity | |
include ActiveModel::Conversion | |
include ActiveModel::Naming | |
EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i | |
attr_accessor :name, :message, :email | |
validates :name,:presence => true | |
validates :message,:presence => true | |
validates :email,:presence => true,:format => EMAIL_REGEX | |
def initialize(options={}) | |
@name = options[:name] | |
@email = options[:email] | |
@message = options[:message] | |
end | |
def deliver_contact_us | |
Notification.contact_us(name,email,message).deliver if self.valid? | |
end | |
# OVERIDDEN METHOD FOR ACTIVE MODEL TO NOT ACT AS A ACTIVERECORD MODEL | |
def persisted? | |
false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment