Code in the lib directory


I’ve put code very similar to the following code in the lib directory.

module Common
A_CONSTANT = [ ‘one’, ‘two’, ‘three’, ‘four’ ]

def a_method(session)
if !session[:d] then
session[:d] = ‘a string constant’
… more of the same …

The file containing this code is named ‘common.rb’. The constant and
method are then referenced in a number of my controllers similar to
the following:

class MyController …
def index

some_variable = Common::A_CONSTANT



When the app is run, ruby/rails is able to resolve the A_CONSTANT
reference, but I can’t seem to get the method to resolve. I’ve tried
using require in the controller files, I’ve tried delimiting the
method with double colons and I’ve tried different names for the
module while making sure the file and module names in sync. What am I
doing wrong?