尝试发送邮件时未定义的方法记录器

时间:2012-03-11 19:36:02

标签: ruby-on-rails

当我尝试使用邮件程序发送邮件时收到以下错误。我有一个表单,允许用户填写姓名,电子邮件和消息。单击提交按钮会发布到ContactsController的send_mail操作。

[2012-03-11 14:31:00] ERROR NoMethodError: undefined method `logger' for ActionMailer::Base:Class
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/actionmailer-3.2.2/lib/action_mailer/log_subscriber.rb:17:in `logger
'
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/actionpack-3.2.2/lib/action_view/template.rb:285:in `to_proc'
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.2.2/lib/active_support/log_subscriber.rb:76:in `map'

        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.2.2/lib/active_support/log_subscriber.rb:76:in `flus
hable_loggers'
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.2.2/lib/active_support/log_subscriber.rb:84:in `flus
h_all!'
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/railties-3.2.2/lib/rails/rack/logger.rb:28:in `call_app'
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/railties-3.2.2/lib/rails/rack/logger.rb:16:in `call'
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/actionpack-3.2.2/lib/action_dispatch/middleware/request_id.rb:22:in
`call'
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/rack-1.4.1/lib/rack/runtime.rb:17:in `call'
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.2.2/lib/active_support/cache/strategy/local_cache.rb
:72:in `call'
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/rack-1.4.1/lib/rack/lock.rb:15:in `call'
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/actionpack-3.2.2/lib/action_dispatch/middleware/static.rb:61:in `cal
l'
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/railties-3.2.2/lib/rails/engine.rb:479:in `call'
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/railties-3.2.2/lib/rails/application.rb:220:in `call'
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/rack-1.4.1/lib/rack/content_length.rb:14:in `call'
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/railties-3.2.2/lib/rails/rack/log_tailer.rb:14:in `call'
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/rack-1.4.1/lib/rack/handler/webrick.rb:59:in `service'
        C:/dev/tools/Ruby187/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
        C:/dev/tools/Ruby187/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
        C:/dev/tools/Ruby187/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
        C:/dev/tools/Ruby187/lib/ruby/1.8/webrick/server.rb:162:in `start'
        C:/dev/tools/Ruby187/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
        C:/dev/tools/Ruby187/lib/ruby/1.8/webrick/server.rb:95:in `start'
        C:/dev/tools/Ruby187/lib/ruby/1.8/webrick/server.rb:92:in `each'
        C:/dev/tools/Ruby187/lib/ruby/1.8/webrick/server.rb:92:in `start'
        C:/dev/tools/Ruby187/lib/ruby/1.8/webrick/server.rb:23:in `start'
        C:/dev/tools/Ruby187/lib/ruby/1.8/webrick/server.rb:82:in `start'
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/rack-1.4.1/lib/rack/handler/webrick.rb:13:in `run'
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/rack-1.4.1/lib/rack/server.rb:265:in `start'
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/railties-3.2.2/lib/rails/commands/server.rb:70:in `start'
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/railties-3.2.2/lib/rails/commands.rb:55
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/railties-3.2.2/lib/rails/commands.rb:50:in `tap'
        C:/dev/tools/Ruby187/lib/ruby/gems/1.8/gems/railties-3.2.2/lib/rails/commands.rb:50
        script/rails:6:in `require'
        script/rails:6

我的控制器如下:

class ContactsController < ApplicationController
  def mail

    end

  def send_mail
    ContactMailer.email(params[:email], params[:name], params[:message]).deliver
  end
end

我的邮件看起来像:

class ContactMailer < ActionMailer::Base
  default :from => "<from>"

  def email(email, name, message)
    @message = message
    mail(:to => "<email>", :subject => "<message>" + name, :from => email)
  end
end

1 个答案:

答案 0 :(得分:2)

问题是项目中有一个类重写邮件。如果有人遇到同样的问题,只需删除或重命名邮件类/模型。