I'm building a contact form in Rails 3 using this Railscast: http://railscasts.com/episodes/326-activeattr?view=asciicast
I know that the only thing I'm doing wrong is filling out where the message should be sent. I used the following code to send the message:
mail(:to => "me@myemail.com")
However, this doesn't seem to work, because everytime I submit the form, I get this error:
NoMethodError in MessagesController#create
undefined method `mail' for #<MessagesController:0x00000103734bd8>
Application Trace | Framework Trace | Full Trace
app/controllers/messages_controller.rb:10:in `create'
What should I replace this line with to send the message?
messages_controller.rb
class MessagesController < ApplicationController
def new
@message = Message.new
end
def create
@message = Message.new(params[:message])
if @message.valid?
UserMailer.contact_message(@message).deliver
redirect_to root_url, notice: "Message sent! Thank you for contacting us."
else
render "new"
end
end
end
user_mailer.rb
class UserMailer < ActionMailer::Base
def contact_message(message)
@message = message
mail(:to => "myemail@mymail.com", :subject => "New Message")
end
end
setup_mail.rb
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "mywebsite.com",
:user_name => "myemail",
:password => "secret",
:authentication => "plain",
:enable_starttls_auto => true
}
ActionMailer::Base.default_url_options[:host] = "localhost:3000"