Rails 3.2.8 Actionmailer - 堆栈级别太深PLUS未初始化的常量Mail :: Ruby19

时间:2012-12-27 07:30:17

标签: ruby-on-rails actionmailer

我正在关注StackOverflow帖子中引用的教程,以获取简单的联系表单。教程在这里:http://matharvard.ca/posts/2011/aug/22/contact-form-in-rails-3/

所有内容都是复制/粘贴,并为我的域名和邮件设置更改了一些值。遇到两个非常奇怪的错误:当我第一次提交联系表格时,我得到了一个:

  堆栈级别太深

     

Rails.root:/ Users / me / application

     

应用程序跟踪|框架跟踪|完整跟踪

     

加载以下文件时发生此错误:

     

邮件

     

邮件/解析器/ rfc2822_obsolete

如果我重新提交而不重启rails应用程序,我会得到:

  

未初始化的常量Mail :: Ruby19

     

Rails.root:/ Users / me / application

     

应用程序跟踪|框架跟踪|完整跟踪

     

app / mailers / notifications_mailer.rb:1:在`'

     

app / controllers / contact_controller.rb:11:在'create'

     

加载以下文件时发生此错误:

     

邮件

我认为可能相关的部分是:

class NotificationsMailer < ActionMailer::Base
  default :from => "feedback@mydomain.com"
  default :to => "me@gmail.com"

  def new_message(message)
    @message = message
    mail(:subject => "mydomain Feedback")
  end
end

class Message
  include ActiveModel::Validations
  include ActiveModel::Conversion
  extend ActiveModel::Naming

  attr_accessor :name, :email, :subject, :body

  validates :name, :email, :subject, :body, :presence => true
  validates :email, :format => { :with => %r{.+@.+\..+} }, :allow_blank => true

  def initialize(attributes = {})
    attributes.each do |name, value|
      send("#{name}=", value)
    end
  end

  def persisted?
    false
  end
end

class ContactController < ApplicationController
  def new
    @message = Message.new
  end

  def create
    @message = Message.new(params[:message])        
    if @message.valid?
        NotificationsMailer.deliver_new_message params[:message]
      # NotificationsMailer.new_message(@message).deliver
      redirect_to(root_path, :notice => "Message was successfully sent.")
    else
      flash.now.alert = "Please fill all fields."
      render :new
    end
  end
end

其余模板非常简单,渲染效果很好。

另外,附上gemfile以防我错过了一些明显的冲突:

source 'https://rubygems.org'
gem 'rails', '3.2.8'
gem 'sqlite3'
gem 'redis', '2.1.1'
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'jade'
gem "haml", ">= 3.1.7"
gem "haml-rails", ">= 0.3.5", :group => :development
gem "hpricot", ">= 0.8.6", :group => :development
gem "ruby_parser", ">= 2.3.1", :group => :development
gem "rspec-rails", ">= 2.11.4", :group => [:development, :test]
gem "email_spec", ">= 1.2.1", :group => :test
gem "cucumber-rails", ">= 1.3.0", :group => :test, :require => false
gem "database_cleaner", ">= 0.9.1", :group => :test
gem "launchy", ">= 2.1.2", :group => :test
gem "capybara", ">= 1.1.2", :group => :test
gem "factory_girl_rails", ">= 4.1.0", :group => [:development, :test]
gem "bootstrap-sass", ">= 2.1.0.1"
gem "devise", ">= 2.1.2"
gem "cancan", ">= 1.6.8"
gem "rolify", ">= 3.2.0"
gem "simple_form", ">= 2.0.4"
gem "quiet_assets", ">= 1.0.1", :group => :development
gem "hub", ">= 1.10.2", :require => nil, :group => [:development]
gem 'paperclip'
gem 'aws-sdk'
gem 'aws-s3'
gem "high_voltage"

提前谢谢。

1 个答案:

答案 0 :(得分:0)

我认为来自ContactController.rb的以下代码是罪魁祸首:

NotificationsMailer.deliver_new_message params[:message]

您实际上没有方法名称deliver_new_message

尝试删除它,并取消注释它下面的行:

NotificationsMailer.new_message(@message).deliver

希望这有帮助