Andrew Arrow
Andrew Arrow

Reputation: 4565

how can I send an email from an IronWorker for a rails3 app?

I followed all the docs for IronWorkerNG::Client.new and rails:

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

My .worker file is doing:

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

and my ruby file does:

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

But everytime I get this error:

/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>'

and ResultMailer DOES have an email method:

class ResultMailer < ActionMailer::Base

  def email
    to = '[email protected]'
    mail :from => '[email protected]', :to => to, :subject => "Test"
  end

end

any idea why action_mailer base line 433 is throwing that error? I can call ResultMailer.email.deliver from the console on my local system just fine. This error is on production with heroku and iron.io.

Upvotes: 1

Views: 187

Answers (1)

Andrew Arrow
Andrew Arrow

Reputation: 4565

ah, sometimes writing out the question on stackoverflow makes you see the problem. I needed:

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

without the 3.2.8 version it was using an old old version of action mailer.

Upvotes: 4

Related Questions