我已经集成了Sendgrid传入解析Webhook API,它正确地将电子邮件对象发布到我的rails应用程序。在app上我使用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
这是我使用的宝石版本:
#Process incoming mail from sendgrid smtp server
gem 'griddler', "~> 1.1.0"
gem 'griddler-sendgrid', "~> 0.0.1"
这是基于griddler github
上提供的文档任何人都可以帮助我解决我在这里失踪的问题。另外,为什么我在日志中看不到以下行?
"initialized Email Processor\n\n\n\n\n\n\n\n"
以下是定义路线的行
mount_griddler
编辑:据我所知,rails并没有直接添加任何这样的类。 奇怪的是,我能够看到&#39;过程&#39;可用于&#39; EmailProcessor&#39;课程在&#39; rails console&#39;:
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]
由于
答案 0 :(得分:3)
问题是,EmailProcessor
类没有加载rails应用程序启动。将以下行添加到application.rb
可以实现神奇:
config.autoload_paths += %W(#{config.root}/app/mailers/email_processor.rb)
注意:每次对email_processor.rb进行更改时,您都需要重新启动服务器。
感谢Joel Oliveira(Griddler的作者)回复我的个人电子邮件并指出了问题:)