I have a file in the lib directory that uses some constants defined in a model, like:
class User < ActiveRecord::Base
MAX_EMAIL_ADDRESS_LENGTH = 255
en
The first part was done right:
config.autoload_paths += %W(#{config.root}/lib)
Next, it is important, module
module Foo
...
end
must be placed into
lib/foo.rb
file.
And then, it can be include
d into application code.
class Comment < ActiveRecord::Base
include Foo
...
end
If file foo.rb
from lib directory is not intended to be included (however it is probably a wrong way), then to use Rails models and other stuff inside this code you should put this into foo.rb:
require_relative "../config/environment.rb"