使用未初始化的常量在rails中创建新模型

时间:2014-01-30 20:00:24

标签: ruby-on-rails

我已经创建了一个新模型,以便在我的rails应用程序上创建联系表单。

重新启动服务器后,当我尝试运行它时,我得到了

  

未初始化的常量MailForm

我的控制器代码是

        class ContactsController < ApplicationController
      def new
        @contact = Contact.new
      end

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

我的contact.rb模型是

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

  # Declare the e-mail headers. It accepts anything the mail method
  # in ActionMailer accepts.
  def headers
    {
      :subject => "Contact Guide To Be",
      :to => "hello@guidetobe.co.uk",
      :from => %("#{name}" <#{email}>)
    }
  end
end

我意识到这是一个相当普遍的错误,并且想知道是否有人可以指出我正确的方向来解决我做错了什么?

0 个答案:

没有答案