New Discussion

Notifications

You’re not receiving notifications from this thread.

Making a contacts form page, getting LoadError

0
Rails

Hello. I'm trying to create a contact page that emails me directly from the contact me page of my portfolio site. I created the contact form model by following this tutorial on YouTube. But I'm getting this error shown in the screenshot. ! https://imgur.com/a/kFCMsDc
Below is my contact.rb file


class ContactForm < MailForm::Base
  attribute :name,      :validate => true
  attribute :email,     :validate => /\A([\W\.%\+\-]+)@([\W\-]+\.)+([\W]{2,})\z/i
  attribute :message,   :validate => true
  attribute :nickname,  :captcha  => true

  def headers 
    {
    :subject => "Contact Form",
    :to => "kwilliamson0232@gmail.com",
    :from => %("#{name}" <#{email}>)
    } 
  end
end

And here is my contacts_controller.rb file:

class ContactsController < ApplicationController

  def index

  end

  def new
    @contact = Contact.new
  end

  def create
    @contact = Contact.new(params[:contact])
    @contact.request = request
    if @contact.deliver
      flash.now[error] = nil
    else
      flash.now[:error] = 'Cannot send message.'
      render :new
    end
  end

end

It's highlighting that @contact = Contact.new line in the error. I'm just not understanding why. I need to define it from what the error says, but I just don't know where. Can someone help me?

Join the discussion
Create an account Log in

Learning Ruby on Rails? Join our newsletter.

We won't send you spam. Unsubscribe at any time.