次のようなジョブを作成しました。
class SendEmailJob < ActiveJob::Base
queue_as :default
def perform(user)
@user = user
UserMailer.welcome_email(@user).deliver_later
end
end
それは私のメーラーを使用します:
class UserMailer < ActionMailer::Base
def welcome_email(user)
@user = user
mg_client = Mailgun::Client.new ENV['api_key']
message_params = {
:from => ENV["gmail_username"],
:to => @user.email,
:subject => "Welcome",
:text => "This is a welcome email"
}
mg_client.send_message ENV["domain"], message_params
end
end
私のコントローラー:
SendEmailJob.set(wait: 20.seconds).perform_later(@user)
次のエラーが発生し続けます: NoMethodError (SendEmailJob:Class の未定義メソッド「set」):
編集 config/application.rb require File.expand_path('../boot', FILE )
require 'rails/all'
require 'active_job'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module LinkbuilderPro
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
end
end
レール 4.1.8