1

我关注了 IronWorkerNG::Client.new 和 rails 的所有文档:

https://github.com/iron-io/iron_worker_rails_example

我的 .worker 文件正在执行:

runtime 'ruby'

name 'CompanyList'

merge_gem 'activerecord'
merge_gem 'actionmailer'
merge_gem 'pg'
merge_gem 'aws-s3'

dir '../app/models'
file '../app/mailers/result_mailer.rb'
file "../app/views/result_mailer/email.html.erb", "result_mailer"

exec 'company_list.rb'
remote

我的红宝石文件确实:

require 'action_mailer'
require 'active_record'
require 'aws/s3'
require 'pg'
require 'models/company_list.rb' 
require 'result_mailer.rb'

puts "Starting CompanyList worker at #{Time.now}"

ActiveRecord::Base.establish_connection(params['database'])
mailer_config = params['mailer'].inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo }
#ActionMailer::Base.prepend_view_path('.')
ActionMailer::Base.view_paths = ['.']
ActionMailer::Base.smtp_settings = mailer_config
ActionMailer::Base.delivery_method = :smtp

但每次我得到这个错误:

/task/__gems__/gems/actionmailer-2.3.18/lib/action_mailer/base.rb:433:
in `method_missing': undefined method `email' for ResultMailer:Class 
(NoMethodError)
from /task/models/company_list.rb:16:in `process_file'
from /task/company_list.rb:18:in `<top (required)>'
from /usr/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from __runner__.rb:213:in `<main>'

并且 ResultMailer 确实有一个电子邮件方法:

class ResultMailer < ActionMailer::Base

  def email
    to = 'andrew@testdomain.com'
    mail :from => 'test@testdomain.com', :to => to, :subject => "Test"
  end

end

知道为什么 action_mailer 基线 433 会抛出该错误吗?我可以从本地系统上的控制台调用 ResultMailer.email.deliver 就好了。Heroku 和 Iron.io 生产时出现此错误。

4

1 回答 1

4

啊,有时在stackoverflow上写出问题会让你看到问题。我需要:

merge_gem "activerecord", "=3.2.8"
merge_gem 'actionmailer', '=3.2.8'

如果没有 3.2.8 版本,它使用的是旧版本的 action mailer。

于 2013-09-18T04:38:06.310 回答