All threads / Making a contacts form page, getting LoadError

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Making a contacts form page, getting LoadError

Kyle Williamson asked in 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 => "[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?

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 34,674+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.