提交自定义邮件进程时出错(每当插件时)

时间:2010-02-01 21:22:42

标签: ruby-on-rails ruby-on-rails-plugins

我正在尝试使用Whenever插件for rails在特定时间执行模型过程。

当我尝试在User模型中使用mail_out进程时,出现以下错误。有人可以指出我出错的方向吗?

/var/lib/gems/1.8/gems/rails-2.3.5/lib/commands/runner.rb:48: /var/lib/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1567:in `find_from_ids': Couldn't find User without an ID (ActiveRecord::RecordNotFound)
    from /var/lib/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:616:in `find'
    from /home/tnederlof/Dropbox/Ruby/daily_trailer/app/models/user.rb:9: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

我的schedule.rb如下:

   every 1.day, :at => '5:30 am' do
    runner "User.mail_out"
  end

我的用户模型是:

class User < ActiveRecord::Base

  acts_as_authentic

  def self.mail_out

    weekday = Date.today.strftime('%A').downcase

    @users = find(:conditions => "#{weekday}sub = t")

    @users.each { |u| UserMailer.deliver_mail_out(u)}   


  end

end

我的User_mailer是:

class UserMailer < ActionMailer::Base
    def mail_out(users)
    @recipients = { }
    users.each do |user|
      @recipients[user.email] = { :name => user.name }
    end


    from        "no-reply@dailytrailer.net"
    subject     "Check out the trailer of the day!"
    body        :user => user
  end

end

迁移:

  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

1 个答案:

答案 0 :(得分:1)

改变这个:

find(:conditions => "#{weekday}sub = t")

find(:all, :conditions => "#{weekday}sub = t")