[英]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
這是我的輸入表
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.