【发布时间】:2015-10-09 18:40:23
【问题描述】:
我在使用send() 调用方法时遇到问题,同时将所述方法传递给对象。我收到undefined method ``employee_feedback(#<WorkItem:0x000000057cc7c0>)' for WorkItemMailer:Class 错误。
这是在我的 work_item.rb 模型中:
def send_work_item_mail
forms_needing_mail = ["employee", "install", "repair"]
if forms_needing_mail.include?(self.form)
WorkItemMailer.send("#{self.form}_feedback(#{self})").deliver_now
end
end
被称为:
@work_item.send_work_item_mail
在我的 work_items_controller.rb 中
以下是我邮件中的方法:
def employee_feedback(work_item)
@work_item = work_item
@employee = User.find_by(id: @work_item.employee)
@manager = User.find_by(id: @employee.manager)
mail to: @manager.email, subject: "Employee feedback for #{@employee.name}"
end
是我使用的发送不正确,还是这里有其他问题?
【问题讨论】:
-
`` 是错字还是出现在异常中?如果不是错字,这就是问题所在。
-
错字。在将其粘贴到我的解释中时添加它,因为 ` 正在阻止代码格式正常工作。
-
元编程标签应该被移除。
send是最基础的。 -
@CarySwoveland:嗯,不是那么基本。但是,是的,远非“元”。
-
@Sergio,我一直认为
puts "It's a fine day"是send(:puts, "It's a fine day.")的语法糖(用于公共方法)。
标签: ruby-on-rails ruby metaprogramming