2

In my project, I have written few classes under lib folder but rails is not detecting those classes in production environment. I get the uninitalized Constant error.

I use Apache in the production environment and rails script/server in the development environment.

Is anything wrong with RAILS_ROOT environment? Can anyone suggest how to overcome this problem?

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
sharath
  • 176
  • 1
  • 10

2 Answers2

1

I am not sure about Rails, but you achieve that in Ruby by this: (it will work in rails too, but rails must be having some elegant way)

require File.join(File.dirname(__FILE__), "lib",'your_module_name')
include your_module_name

Try this in config/application.rb (I assume you have rails3)

config.load_paths += %W( #{config.root}/lib )

Update: Rails - why would a model inside RAILS_ROOT/lib not be available in production mode?

Community
  • 1
  • 1
zengr
  • 38,346
  • 37
  • 130
  • 192
0

Ensure that the name of your file matches the name of the class or module defined in it, accounting for any directories.

ie:

lib/my_new_class.rb

class MyNewClass
end

Or if you have a directory hierarchy:

lib/my_files/my_module.rb

module MyFiles
  module MyModule
  end
end
Peter Brown
  • 50,956
  • 18
  • 113
  • 146