I’m trying send flash messages and welcome notices to users if it’s their first time commenting; basically, something like this:
class CommentObserver < ActiveRecord::Observer
def after_save(comment)
if comment.user.new?
Mailer.deliver_welcome_package(comment)
flash[:notice] = "Welcome! We just delivered a welcome package to your email"
end
end
end
I’m not sure how I should display that flash message for users after they create their first comment. Should I put that flash message in the controller (with an additional “if comment.user.new?”) or is there a way to display the flash message more efficiently?
Putting the flash message in the method seems fine to me.
I usually have a helper method in my application_helper file that checks flash and diplays.
I have three types of messages, notice, warning, and error, this checks to see if any of them are set, if so it prints them out, if not then nothing is printed.
In my layout i then have..