我在Order
Rails 应用程序的模型中,我希望在其中调用Email
类实例的方法。
第一个方法采用Email
类的实例(在本例中称为email
)。它工作得很好。
def recursive_search_mails(user, settings)
emails = user.emails.where(:datetime.gte => self.datetime)
emails.each do |email|
notification = email.test_if_notification(user, settings)
if notification == true
email.destroy
return
end
correspondance = email.test_if_correspondance(user, settings)
if correspondance == true
email.destroy
return
end
end
end
上述代码的一个更简洁的版本是这个:
def recursive_search_mails(user, settings)
emails = user.emails.where(:datetime.gte => self.datetime)
emails.each do |email|
%w(notification, correspondance).each do |type|
is_type = email.send("test_if_#{type}", user, settings)
if is_type == true
email.destroy
return
end
end
end
end
但是,它会引发此错误:
2013-05-09T16:36:11Z 71266 TID-owr7xy0d0 WARN: undefined method `test_if_notification,' for #<Email:0x007fd3a3ecd9b0>
怎么会这样?