1

在我的辅导课程模型中,我有在不同时间触发提醒文本的代码。一切正常,直到我尝试了一些重构,现在我遇到了问题。

def send_reminder_text(texts_batch)
    texts_batch.each do |text|
        page_number = Refugee.find(text.refugee_id)[:last_page]
        body_of_text = text[:begin_time].in_time_zone.strftime("Burma Reminder: upcoming session at %I:%M%p beginning on page #{page_number}. 
            Please email jek2141@columbia.edu to reschedule or cancel the session.") 
        text.begin_text(body_of_text)
    end
end

def self.deliver_pm_reminder_text
    texts_batch = TutoringSession.batch_for_pm_reminder_text
    send_reminder_text(texts_batch)
end

def self.deliver_just_before_reminder_text
    texts_batch = TutoringSession.batch_for_just_before_reminder_text
    send_reminder_text(texts_batch)
end

当我调用该deliver_just_before_reminder_text函数时,我收到以下错误消息:

irb(main):006:0> TutoringSession.send_reminder_text
NoMethodError: undefined method `send_reminder_text' for #<Class:0x00000003cfe5d8>
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record   /base.rb:1088:in `method_missing'
from (irb):6
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.1/lib/rails/commands/console.rb:45:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.1/lib/rails/commands/console.rb:8:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.1/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

send_reminder_text尽管上面已经明确定义了这一事实。

4

1 回答 1

3

您的方法声明指定该方法在TutoringSession类的对象上:

def send_reminder_text(texts_batch)

但是你试图调用它,就好像它是类本身的一个方法:

irb(main):006:0> TutoringSession.send_reminder_text

尝试将您的定义更改为:

def self.send_reminder_text(texts_batch)
于 2012-06-19T01:06:56.453 回答