클래스는 /lib/email_helper.rb
에 정의되어 있습니다. 클래스는 컨트롤러 또는 백그라운드 작업에 의해 직접 사용될 수 있습니다./lib 디렉토리에 정의 된 클래스의 ActionView :: Helpers :: DateHelper에 액세스
time_ago_in_words
가 호출
class EmailHelper
include ActionView::Helpers::DateHelper
def self.send_email(email_name, record)
# Figure out which email to send and send it
time = time_ago_in_words(Time.current + 7.days)
# Do some more stuff
end
end
, 작업이 다음 오류와 함께 실패합니다 :
undefined method `time_ago_in_words' for EmailHelper
가 어떻게 내 EmailHelper
클래스의 컨텍스트에서 time_ago_in_words
도우미 메서드에 액세스 할 수 있습니다 그것은 다음과 같이 보입니다? 관련 모듈이 이미 포함되어 있습니다.
helper.time_ago_in_words
및 ActionView::Helpers::DateHelper.time_ago_in_words
도 사용하지 않으려 고 시도했습니다.
. 클래스 메서드 내에서'time_ago_in_words'를 사용하려고 시도했다는 사실을 간과했습니다. 일반적으로 인스턴스 메서드에서 다른 곳에서 사용한 적이 있습니다. 감사! – ACIDSTEALTH