尝试获取抽成任务以发送电子邮件通知

Trying to get a rake task to send an email notification if

我的问题是,每次我尝试 运行 rake check_pending 时,我都会收到错误消息。有人可以帮助我,让我知道我可能做错了什么。非常感谢任何帮助!

这是我的错误

rake check_pending
rake aborted!
NoMethodError: undefined method `find_all_by_approve_disapprove' for Entry (call 'Entry.connection' to establish a connection):Class
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record /dynamic_matchers.rb:26:in `method_missing'
/home/programmer/Test_app/app/models/entry.rb:45:in    `check_pending'
/home/programmer/Test_app/lib/tasks/check_pending.rake:4:in `block in <top (required)>'
Tasks: TOP => check_pending
(See full trace by running task with --trace)

这是我的模型

class Entry < ActiveRecord::Base

  def self.check_pending #This checks if a time off entry is still pending if so then send an email to the manager reminding them of the pending request.
    check_pending = Entry.find_all_by_approve_disapprove('3')
    if approve_disapporve == '3'
       EntryMailer.check_pending(@entry).deliver
    end
  end
end

这是我的佣金任务

desc "Looks at pending request if the are still marked pending sends a  email to the manager for the request"
task :check_pending => :environment do
Rails.logger.info "Check Pending: Finding all pending."
Entry.check_pending
Rails.logger.info "Found Pending: Check complete."
Rails.logger.flush
end

这是我的时间表

every :day, :at => "9am" do
rake "check_pending"
end

这是我的table条目

  ID    NUMBER(38,0)    
  CREATED_AT    DATE        
  UPDATED_AT    DATE    
  APPROVE_DISAPPROVE    VARCHAR2(255 BYTE)
  EMP_MAIL_ADDR  VARCHAR2 (2555 BYTE)

除了这个问题还有我的entry_mailer

class EntryMailer < ActionMailer::Base

  def check_pending(entry)
    @entry = entry

    mail to: entry.emp_mail_addr, subject: '(TEST) You have pending time off request'
  end
end

试试这个

Entry.where(approve_disapprove: '3') 

以及为什么 3 是字符串你也可以这样使用

Entry.where(approve_disapprove: 3)

您可以遍历所有待定条目并向它们发送电子邮件

def self.check_pending
    check_pending = Entry.find_all_by_approve_disapprove(3)
    check_pending.each do |entry|
        EntryMailer.check_pending(entry).deliver
    end 
end

然后在您的 EntryMailer

def check_pending(entry)
    @entry = entry
    mail to: @entry.emp_mail_addr, subject: '(TEST) You have pending time off request'
end