Forum: Ruby on Rails Uninitialized constant error

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jerry M. (Guest)
on 2008-12-18 07:53
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
Jerry M. (Guest)
on 2008-12-19 10:27
> 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.
This topic is locked and can not be replied to.