Reputation: 853
I am trying to use the delayed::job gem to delay when messages are sent, and when I try and run the code i get the error:
uninitialized constant RemindersController::RemindLater
The code I have in my controller is :
require 'delayed_job_active_record'
require 'delayed_job'
class RemindersController < ApplicationController
def index
end
def new
@reminder = Reminder.new
end
def create
@reminder = Reminder.create(reminder_params)
@reminder.user = current_user
@reminder.save
Delayed::Job.enque(RemindLater.new(@reminder.id), 0, @reminder.time)
redirect_to reminders_path
end
private
def reminder_params
params.fetch(:reminder, {}).permit(:text, :phone_number, :time, :picture, :favorite)
end
end
in my /lib/remind_later.rb I have
class RemindLater < Struct.new(:reminder_id)
def perform
Reminder.send_text_message(reminder_id)
end
end
Does anyone know why I am getting this error? thanks.
Upvotes: 1
Views: 919
Reputation: 24347
Make sure that you've added the lib directory the the autoload_paths
in config/application.rb:
config.autoload_paths << Rails.root.join('lib')
Upvotes: 1