-
-
Save nicedawg/c28d5a14e7182d606ef5bf01b68779ee to your computer and use it in GitHub Desktop.
[Beginning Rails 6] Listing 13-5. sending "comment added" mailer asynchronously
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 Comment < ApplicationRecord | |
belongs_to :article | |
validates :name, :email, :body, presence: true | |
validate :article_should_be_published | |
after_create :email_article_author | |
def article_should_be_published | |
errors.add(:article_id, 'is not published yet') if article && !article.published? | |
end | |
def email_article_author | |
NotifierMailer.comment_added(self).deliver_later | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment