【发布时间】:2015-03-12 13:03:37
【问题描述】:
我的问题是每次我尝试运行 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) -
您的建议消除了该错误,但现在我收到此错误...
-
NoMethodError: 未定义方法 `emp_mail_addr' for Entry (调用 'Entry.connection' 建立连接):Class
-
我用这个错误的所有信息更新了问题@Sontya
-
EntryMailer.check_pending(@entry).deliver在此方法中的模型中@entry不存在
标签: ruby-on-rails ruby-on-rails-4 activerecord rake