Code in the lib directory

Hi,

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’
end
… more of the same …
end
end

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

Common.a_method(session)

end

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?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs