New module method in /lib not loading in rails console

Viewed 586

I have a module located in my rails app under /lib. I just added a new method to this module and want to test it out using the rails console.

I start the rails console, include the module with include ModuleName and then try to run the function with function_name(parameter)

Then I get a NoMethodError (undefined method 'function_name' for main:Object)

I've tried multiple ways of fixing this, it seems that having config.eager_load_paths << Rails.root.join('lib') in the config/application.rb file is the way to get the '/lib' folder loading. This does not work for me.

Does anyone know why my new method will not load in my rails console?

Additionally, I can call the method from the app via a controller. So this issue is specific to the rails console.

1 Answers

You must require the file explicitly in the rails console. require "./lib/your_file_name.rb"

Related