2012-06-19 2 views
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 [email protected] 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 четко определено выше.

ответ

3

Ваше объявление метода указывает, что этот метод на объектах TutoringSession класса:

def send_reminder_text(texts_batch) 

Но вы пытаетесь назвать его, как если бы это был метод на самом классе:

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

Попробуйте изменить свое определение на:

def self.send_reminder_text(texts_batch) 
Смежные вопросы