Skip to main content
Ask A Question
Notifications
You’re not receiving notifications from this thread.
Subscribe

Making a contacts form page, getting LoadError

Rails • Asked by Kyle Williamson

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 => "[email protected]",
    :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?


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,152+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.