Last active
August 12, 2016 13:15
-
-
Save licatajustin/f348b5a5782bf5d38d35 to your computer and use it in GitHub Desktop.
Rails callbacks for http://stackoverflow.com/questions/31854717/rails-bootstrap-flash-notice-success-is-now-red-and-not-green#31854717
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 Contact < ActiveRecord::Base | |
after_create :send_email | |
private | |
def send_email | |
ContactMailer.contact_email(self).deliver | |
end | |
end |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
</head> | |
<body> | |
<p>New Message from Hoot and Holla's Contact form, from <%= "#{@contact.name}, #{@contact.email}" %></p> | |
<p><%= @contact.phone %></p> | |
<p><%= @contact.event %></p> | |
<p><%= @contact.body %></p> | |
</body> | |
</html> |
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
def contact_email(contact) | |
@contact = contact | |
mail(from: @contact.email, subject: 'Contact Form Message').deliver | |
end | |
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
def create | |
@contact = Contact.new(contact_params) | |
if @contact.save | |
flash[:success] = 'Message Sent.' | |
redirect_to new_contact_path | |
else | |
flash[:danger] = 'Error occurred, messgage not sent.' | |
redirect_to new_contact_path | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You're welcome @RuNpiXelruN -- sorry for the delay -- no notifications on Gists yet I guess.