开发者

User Mailer Failing

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        "no-reply@dailytrailer.net"
    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


I'm not sure if this is the complete solution (what error are you getting?), but it's something that needs to be fixed: on the line body :user => user, the user variable is not defined. Do you mean to do :user => @recipients?


One thing I'm noticing in your code is that your mailer class is not deriving from Postage::Mailer.

So first make sure you have the latest PostageApp plugin installed and then look at some example code here: http://postageapp.com/docs/rails

There's also a sample app here: http://blog.postageapp.com/2009/11/rails-example-app/

Another detail I noticed in your code is in the line body :user => user is not needed because you're not using the user variable in your view besides the fact that, as Alex mentioned, it's not defined at that point.

Hope that helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜