Skip to content

Instantly share code, notes, and snippets.

@licatajustin
Last active August 12, 2016 13:15
Show Gist options
  • Save licatajustin/f348b5a5782bf5d38d35 to your computer and use it in GitHub Desktop.
Save licatajustin/f348b5a5782bf5d38d35 to your computer and use it in GitHub Desktop.
class Contact < ActiveRecord::Base
after_create :send_email
private
def send_email
ContactMailer.contact_email(self).deliver
end
end
<!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>
def contact_email(contact)
@contact = contact
mail(from: @contact.email, subject: 'Contact Form Message').deliver
end
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
@RuNpiXelruN
Copy link

Hey Justin, a quick question...again, sorry! I've tidied up my code and files as you've suggested here but am getting a nomethoderror in contacts#create?

Showing /home/action/workspace/hootandholla_lp/app/views/contact_mailer/contact_email.html.erb where line #9 raised:

undefined method `event' for #Contact:0x000000049be368

<%= @contact.event %>

Any ideas as to why??

Sorry to ask again..i really appreciate you taking the time to do all this though!

@RuNpiXelruN
Copy link

Actually, apologies for jumping the gun here...i've managed to work it out myself. @contact.event needed to be changed to @contact.event_type and @contact.body needed to be changed to @contacts.comments.

Thanks again Justin for pointing me in the right direction :)

@licatajustin
Copy link
Author

You're welcome @RuNpiXelruN -- sorry for the delay -- no notifications on Gists yet I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment