vendredi 15 décembre 2017

LoadError (Unable to autoload constant XYZ, expected XYZ.rb to define it) in development environment

Recently, I can't make changes to my app without restarting my development server, otherwise I receive this error:

LoadError (Unable to autoload constant BotFeedback, expected ../../bot_feedback.rb to define it)

This hasn't been a problem before and I'm not entirely sure why this has become a problem. I have these settings configured in application.rb:

# Auto-load the bot and its subdirectories
config.paths.add File.join('app', 'bot'), glob: File.join('**', '*.rb')
config.autoload_paths += Dir[Rails.root.join('app', 'bot', '*')]

My app/bot folder includes files such as:

bot.rb with:

require "#{Rails.root}/app/bot/orderbot.rb"
Bot.on :message do |message|
  OrderBot.new()
  ..
end

def somefunction
  OrderBot.new()
  ..
end

orderbot.rb with:

require "#{Rails.root}/app/bot/bot_feedback.rb"
require "#{Rails.root}/app/bot/bot_demo.rb"
require "#{Rails.root}/app/bot/bot_helper.rb"
class OrderBot
  include BotFeedback
  include BotDemo
  include BotHelper
  (many more includes)
  ..
end

bot_feedback.rb with:

require "#{Rails.root}/app/models/concerns/sharedmethods.rb"
class OrderBot
  include Sharedmethods
  module BotFeedback
    ...
  end
end

bot_demo.rb with:

class OrderBot
  module BotDemo
    ..
  end
end

bot_helper.rb with:

require "#{Rails.root}/app/models/concerns/sharedmethods.rb"
class OrderBot
  include Sharedmethods
  module BotHelper
    ...
  end
end

My guess is that including the sharedmethods file is causing this because I don't see anything else being a problem. Changing the sharedmethods file in the rails app has always seemed to require restarting the server.

I would appreciate any help/suggestions.

Aucun commentaire:

Enregistrer un commentaire