我希望在X秒后运行延迟功能。 X由对象的字段确定。
我试过了:
# after_create this function is triggered
def save_distance
update_attribute :distance, 5
end
# function gets delayed by X seconds (X = field named "timespan" of my object)
handle_asynchronously :save_distance, :run_at => Proc.new { timespan.seconds.from_now }
但它不起作用,返回:
undefined local variable or method `timespan' for #<Class:0x007f9b9d4f4c88>
怎么做?
答案 0 :(得分:1)
您需要将参数传递给proc
handle_asynchronously :save_distance, :run_at => Proc.new {|object| object.timespan.seconds.from_now }