我已经集成了 Sendgrid 传入解析 Webhook API,它正确地将电子邮件对象发布到我的 rails 应用程序。在应用程序上,我使用 griddler gem 来捕获并进一步处理电子邮件数据。但我得到以下异常:
Sent mail to chandan@exmaple.com (77.6ms)
F, [2014-11-14T17:48:05.851336 #24799] FATAL -- :
NoMethodError (undefined method `process' for #<EmailProcessor:0x0000000a2ad5f0>):
griddler (1.1.0) app/controllers/griddler/emails_controller.rb:19:in `public_send'
griddler (1.1.0) app/controllers/griddler/emails_controller.rb:19:in `process_email'
griddler (1.1.0) app/controllers/griddler/emails_controller.rb:4:in `block in create'
griddler (1.1.0) app/controllers/griddler/emails_controller.rb:3:in `each'
griddler (1.1.0) app/controllers/griddler/emails_controller.rb:3:in `create'
actionpack (4.1.4) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.1.4) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.1.4) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.1.4) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.1.4) lib/active_support/callbacks.rb:113:in `call'
我在 /mailer/email_processor.rb 中有流程实例方法
class EmailProcessor
def initialize(email)
@email = email
puts "initialized Email Processor\n\n\n\n\n\n\n\n" # Should see this line in log
end
def process
user = User.find_by_email(@email.from[:email])
puts @email.inspect and return if user.blank?
puts "############### @email = #{@email.inspect}###############\n\n\n\n\n\n\n"
end
end
这是 config/initializer/griddler.rb
Griddler.configure do |config|
config.processor_class = EmailProcessor
config.processor_method = :process
config.reply_delimiter = '-- REPLY ABOVE THIS LINE --'
config.email_service = :sendgrid
end
这是我正在使用的 gem 版本:
#Process incoming mail from sendgrid smtp server
gem 'griddler', "~> 1.1.0"
gem 'griddler-sendgrid', "~> 0.0.1"
谁能帮我解决我在这里缺少的东西。另外,为什么我在日志中看不到以下行?
"initialized Email Processor\n\n\n\n\n\n\n\n"
以下是定义路线的行
mount_griddler
编辑:据我所知,rails 不会直接添加任何此类。奇怪的是,我能够在'rails console'中看到'EmailProcessor'类可用的'process'方法:
2.1.4 :005 > x = EmailProcessor.new(1)
initialized Email Processor\n\n\n\n\n\n\n\n
=> #<EmailProcessor:0x007fc6ae5aee08 @email=1>
2.1.4 :006 > x.methods
=> [:process, :blank?, :present?, ...
2.1.4 :014 > EmailProcessor.instance_methods(false)
=> [:process]
谢谢