I create a custom class which I call MyClass in a module MyModule
module MyModule
class MyClass
def initialize
... # Some code here
end
end
end
I save this code in a file called mymodule.rb
I place this file in the lib directory of my rails application, and add the following line to my application.rb
config.autoload_paths += %W(#{config.root}/lib)
When I fire up the rails console and try to use this file. it just doesnt work.
m = MyModule::MyClass.new()
NameError: uninitialized constant MyModule
from (irb):1
from /Users/matt/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.6/lib/rails/commands/console.rb:44:in `start'
from /Users/matt/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.6/lib/rails/commands/console.rb:8:in `start'
from /Users/matt/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.6/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
What do I need to do in order to be able to use that class in the rails console
Any help appreciated
Name the file my_class.rb and place it in the directory my_module. That should fix your problem.