Reputation: 135
It is the first time to interact with observer gem, and after reading the wiki i just cant get it how would it send a message after creating some record in the database here is the code i used from the git hub wiki with changing the names to an existing model name in my project:
class CommentObserver < ActiveRecord::Observer
def after_save(comment)
Notifications.comment("[email protected]", "New comment was posted", comment).deliver
end
end
i dont know what this function do can anyone please explain it to me as it is not clear in the wiki,Thanks.
Upvotes: 0
Views: 130
Reputation: 343
The after_save
callback method is overridden to send a email notification. callbacks are methods which are called at specific points(moment) during the creation of an object. so here the after_save
is called when an Object of type Comment
is saved. you can read more about callbacks here.
Upvotes: 1