-
-
Save danteregis/1109375 to your computer and use it in GitHub Desktop.
models and action mailer
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
#sendemail.rb | |
class Sendemail < ActiveRecord::Base | |
has_many :newsletters, :dependent => :destroy | |
validates_presence_of :subject, :body | |
after_create :deliver_notification | |
protected | |
def deliver_notification | |
SendemailMailer.notification(self).deliver | |
end | |
end | |
#newsletter.rb | |
class Newsletter < ActiveRecord::Base | |
belongs_to :sendemail | |
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i | |
validates_presence_of :name, :email | |
#scope :pending, where(:open => true) | |
#scope :joined, where(:open => false) | |
after_create :deliver_notification | |
protected | |
def deliver_notification | |
NewsletterMailer.deliver_notification(self) | |
end | |
end | |
#sendemail_mailer.rb | |
class SendemailMailer < ActionMailer::Base | |
default :from => "contato@lifetic.com.br" | |
# pelo menos é assim no Rails 2.3.x | |
def notification(newsletter) | |
recipients newsletter.email | |
subject "NEWSLETTER DO POKEMON" | |
body :newsletter => newsletter | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment