为什么我在Heroku任务中收到未定义的方法错误?

时间:2015-08-18 14:52:45

标签: ruby-on-rails heroku

我需要在Heroku中按时发送电子邮件。我在Heroku中有Scheduler插件。 这是我的Cards_controller:

lass CardsController < ApplicationController
  ......
  skip_before_filter :require_login, only: [:send_letters]

  def send_letters
    if Card.created_before(Time.now).any?
      @users = User.all
      @users.each do |user|
        CardMailer.send_expired_cards(user.email).deliver_now
      end
    end
  end
.......

和Card_mailer.rb文件:

class CardMailer < ApplicationMailer
  default from: "new-cards@flashcards.com"

  def send_expired_cards(email)
    @email = email
    @url = "http://flashcards.com"

    @cards = Card.created_before(Time.now)
    mail(to: @email,
         subject: "Простроченные карточки на проверку от сайта Flashcards.com")
  end
end

schedule.rake文件:

desc "This task is called by the Heroku scheduler add-on"
task :update_feed => :environment do
  puts "Updating feed..."
  CardsController.send_letters
  puts "done."
end

运行heroku run rake update_feed后出现错误:

NoMethodError: undefined method `send_letters' for CardsController:Class

怎么了?

0 个答案:

没有答案