Reputation: 2218
I am getting the following error after running bundle exec rake jobs:work
FAILED (0 prior attempts) with NoMethodError: undefined method `post_it' for # Class:0x00000003375e80>
class PostCreationJob < ActiveJob::Base
queue_as :default
def perform(user_id, string, url)
Message.post_it(user_id, string, url)
end
end
class Message < ActiveRecord::Base
def post_it(id, string, url)
scraper = ForumScraper.new
scraper.tpt_login(id)
scraper.make_post(string, url)
end
end
class MessagesController < ApplicationController
def create
@message = Message.new(message_params)
@message.save
PostCreationJob.perform_later(@message.user_id, @message.string, @message.url)
redirect_to :back
flash[:info] = "Posts are being processed."
end
end
I am using Rails 4.2.5
application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(*Rails.groups)
module Workspace
class Application < Rails::Application
config.active_record.raise_in_transactional_callbacks = true
config.active_job.queue_adapter = :delayed_job
end
end
Upvotes: 0
Views: 813
Reputation: 2614
The post_it
method is defined as an instance method, but you're calling it as a class method when you call Message.post_it
, and so the method is not found on the class and raises the no method exception. If you define post_it
as def self.post_it
it will be accessible from the class as a class method.
Upvotes: 3