未定义的方法为 (class) mail_form gem

Undefined method true for (class) mail_form gem

我在 Rails 编程方面 Ruby 相对较新,在尝试使用 mail_form gem 时出现此错误。 The error is in the create function as can be seen

我想我的所有设置都是正确的:

我的模型是这样的:

class Contact < 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 => "(my email)",
      :from => %("#{name}" <#{email}>)
    }
   end
end

我不知道我尝试创建一个只有一个页面的网站是否重要,所以我在页面控制器的 welcome.html.erb 中有创建新联系人的表单,但我正在定义联系人:

def welcome
   @admin = Admin.find(1)
   @projects = Project.all.order('created_at DESC')
   @contact = Contact.new
end

另外我认为这很重要,创建函数(即抛出错误)在联系人控制器中,我不知道是否可以,或者在与 Contact.new(在页面的欢迎功能中):

def create
    @contact = Contact.new(params[:contact])
    @contact.request = request
    if @contact.deliver
      redirect_to(root_path, :notice => "Thank you for contacting me. I will reply shortly!")
    else
      flash.now[:error] = 'Cannot send message.'
    end
end

我还没有在生产中测试过,只是在开发中,也许这不会在生产中发生,但我想知道为什么这会发生在我身上,因为我正在关注 Mackenzie Child 的 tutorial这并没有发生在他身上,我们有相同的代码(除了我试图只在一个视图中实现这一点)。我不知道它是否有帮助,但这是我 config/environments/development.rb:

中的内容
config.action_mailer.delivery_method = :letter_opener

所以在开发中我使用 gem letter_opener 来显示消息而不是发送邮件,尽管这对错误没有任何影响,因为错误在我安装gem.

我搜索了很多地方和所有关于堆栈溢出的问题,但我一无所获。如果你能帮助我,那将不胜感激。

谢谢。

编辑: 我已经在生产中使用 heroku 和 returns 测试了同样的错误:(

好的, 我在 gem 的 github 页面中询问,我可以解决问题。这是在验证 Contact 模型的属性时,我将 :true 声明为一个对象,而它必须只是一个布尔值 true(之前没有冒号)。很高兴知道避免愚蠢的错误。