I’m trying to build a contact form using the approach I saw in the Railscast about ActiveAttr (which gives me a Message model that isn’t backed by a database).
This code is in the controller for Messages:
class MessagesController < ApplicationController
def new
@message = Message.new
end
def create
@message = Message.new(params[:message])
if @message.valid?
# TODO send message here
redirect_to root_url, notice: "Message sent! Thank you for contacting us."
else
render "new"
end
end
end
I don’t know what kind of code I need to write in order for the contact form input (the message) to be sent to a specific email address during the create action. Would someone please give me a general overview of what I need to know or need to set up in order to make this work? Thank you.
You can add something like this.
You will need to create a Mailer. It’s pretty easy and Rails already has a great guide on how to do this. http://guides.rubyonrails.org/action_mailer_basics.html
Create a mailer
rails generate mailer UserMailerThen in your UserMailer
app\mailers\user_mailer.rbThen create your email view
app\views\user_mailer.txt.erb