Ruby on rails 使用未初始化常量在rails中创建新模型
为了在rails应用程序上创建联系人表单,我创建了一个新模型 重新启动服务器后,当我尝试运行它时 未初始化的常量邮件格式 我的控制器代码是Ruby on rails 使用未初始化常量在rails中创建新模型,ruby-on-rails,Ruby On Rails,为了在rails应用程序上创建联系人表单,我创建了一个新模型 重新启动服务器后,当我尝试运行它时 未初始化的常量邮件格式 我的控制器代码是 class ContactsController < ApplicationController def new @contact = Contact.new end def create @contact = Contact.new(params[:contact]
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
class contacts控制器
我的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
class联系人true
属性:email,:validate=>/\A([\w\.%\+\-]+)@([\w\-]+\)+([\w]{2,})\z/i
属性:类型
属性:消息
#声明电子邮件标题。它接受mail方法中的任何内容
#在ActionMailer中接受。
def标题
{
:subject=>“待办联系人指南”,
:to=>“hello@guidetobe.co.uk",
:from=>%(“#{name}”)
}
结束
结束
我意识到这是一个相当普遍的错误,我想知道是否有人能为我指出正确的方向,找出我做错了什么?你能提供整个堆栈跟踪吗?你使用的是哪个版本的rails?我似乎无法正确运行堆栈跟踪,我一直在尝试按照教程进行操作。你能帮忙吗(很抱歉不能这么做)?Rails 4.0.2,是的,我已经绑定了整个跟踪,整个错误都将被复制/粘贴。顺便说一句,你有一个输入错误在未初始化。。。令人困惑的词。该错误表明MailForm未正确安装,请检查您的gemfile是否存在打字错误,并确保它已正确安装。