I have setup a process in my User model to send a bunch of @users to a mailing script, user_mailer.rb
I am using the http://postageapp.com app to send out emails. The users are getting to the User_mailer but I am getting an error from there. Can anyone please point me in the right direction.
User Model:
class User < ActiveRecord::Base
acts_as_authentic
def self.mail_out
weekday =
Date.today.strftime('%A').downcase
@users = find(:all, :conditions => {"#{weekday}sub".to_sym => 't'})
UserMailer.deliver_mail_out(@users)
end
end
User_mailer.rb
class UserMailer < ActionMailer::Base
def mail_out(users)
@recipients = { }
users.each do |user|
@recipients[user.email] = { :zipcode => user.zipcode }
end
from "
[email protected]"
subject "Check out the trailer of the day!"
body :user => user
end
end
mail_out.html.erb
{{zipcode}},
Please check out the trailer of the day at http://www.dailytrailer.net
Thank you!
--
The DailyTrailer.net Team
User db schema
create_table "users", :force => true do |t|
t.string "email"
t.
date "birthday"
t.string "gender"
t.string "zipcode"
t.datetime "created_at"
t.datetime "updated_at"
t.string "crypted_password"
t.string "password_salt"
t.string "persistence_token"
t.string "mondaysub", :default => "f", :null => false
t.string "tuesdaysub", :default => "f", :null => false
t.string "wednesdaysub", :default => "f", :null => false
t.string "thursdaysub", :default => "f", :null => false
t.string "fridaysub", :default => "f", :null => false
t.string "saturdaysub", :default => "f", :null => false
t.string "sundaysub", :default => "f", :null => false
end
Error:
/var/lib/gems/1.8/gems/rails-2.3.5/lib/commands/runner.rb:48: undefined method `name' for #<User:0xb6e8ae48> (NoMethodError)
from /home/tnederlof/Dropbox/Ruby/daily_trailer/app/models/user_mailer.rb:5:in `mail_out'
from /home/tnederlof/Dropbox/Ruby/daily_trailer/app/models/user_mailer.rb:4:in `each'
from /home/tnederlof/Dropbox/Ruby/daily_trailer/app/models/user_mailer.rb:4:in `mail_out'
from /home/tnederlof/.gem/ruby/1.8/gems/actionmailer-2.3.5/lib/action_mailer/base.rb:459:in `__send__'
from /home/tnederlof/.gem/ruby/1.8/gems/actionmailer-2.3.5/lib/action_mailer/base.rb:459:in `create!'
from /home/tnederlof/.gem/ruby/1.8/gems/actionmailer-2.3.5/lib/action_mailer/base.rb:452:in `initialize'
from /home/tnederlof/.gem/ruby/1.8/gems/actionmailer-2.3.5/lib/action_mailer/base.rb:395:in `new'
from /home/tnederlof/.gem/ruby/1.8/gems/actionmailer-2.3.5/lib/action_mailer/base.rb:395:in `method_missing'
from /home/tnederlof/Dropbox/Ruby/daily_trailer/app/models/user.rb:13:in `mail_out'
from (eval):1
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `eval'
from /var/lib/gems/1.8/gems/rails-2.3.5/lib/commands/runner.rb:48
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from script/runner:3