-
-
Save nicedawg/03868d69e4b318cfcd73d87fe495dd23 to your computer and use it in GitHub Desktop.
[Beginning Rails 6] Listing 6-32. The email_article_author Method Specified as an after_create Callback in app/models/comment.rb
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 | |
puts "We will notify #{article.user.email} in Chapter 12" if article.user | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment