Uninitialized constant error


#1

Hi, all. Hoping someone can help me with an error I can’t figure out.

FILE: quote.rb

module BUYER
class Quote

end
end

FILE: quotes_controller.rb

require ‘quote’

class QuotesController

def this_method
q = BUYER::Quote.new(params[:id])
end
end

When I run this_method, I get the error:

uninitialized constant BUYER::Quote

I am able to access other classes from BUYER in exactly the same way,
and do not receive an error. I’m still trying to get used to Ruby’s
conventions, and I wonder if anyone can see anything I did wrong.

I should mention that the two files listed are in different directories.
quote.rb is in a library which I have referenced in environment.rb with
the line

config.load_paths += %W(
#{RAILS_ROOT}/…/software/src/QuoteGenerator/lib )

The classes I mentioned in the previous paragraph, which I am able to
refer to without error, are also located in this lib directory, so I
know it’s not just an issue of not being able to see my includes or
something.

Is the fact that I have two different objects with the same name perhaps
causing problems? I would think this would be resolved by use of the
namespace – err, excuse me, module – syntax.

I’ve seen a bunch of replies to queries of this sort suggesting that
improper pluralization is the problem, so I am hoping that my problem
here is a similarly simple fix.

Please let me know if I am lacking any important info.

Thanks,
Jerry


#2

Is the fact that I have two different objects with the same name perhaps
causing problems? I would think this would be resolved by use of the
namespace – err, excuse me, module – syntax.

This was indeed the problem. I changed the name of the object Quote to
Qquote, updated all references to it, and left the name of the Quote
model as it is. It works now.