Can not find superclass

Y

Yu Co

Hi all,

I've the following:
I defined two classes 'Super' und 'Sub' in two separate files that look
like this:

class Super < ActiveRecord::Base
end

class Sub < Super
end

After compiling 'Sub' I get the following error message "uninitialized
constant Super (NameError)"
Ruby doesn't consider 'Super' as a class but rather as a constant. Does
anyone know how I can avoid this?

Thanks in advance.

Regards,
yussibaer
 
Y

Yu Co

Paul said:
You haven't shown enough code. Does the Sub class file have this at the
top:

require 'super'

That's all of the code I have. I have just two empty classes - one
should be the subclass and the other the superclass.

After writing "require 'super'" at the top of the 'sub'file I get
"uninitialized constant ActiveRecord (NameError)"

Odd, isn't ?
 
Y

Yu Co

Paul said:
Yu Co wrote:

/ ...


Not, it's not odd, it means that, because you put "require 'super'" at
the
top of the sub class file, the sub class found the super class, and you
now
have an new problem. The new problem is the absence of:

require 'activerecord'

at the top of the super class file.

Before, the sub class couldn't find a definition for 'super'. Now super
can't find a definition for 'activerecord'.

Each Ruby source file that requires information from outside itself ...
must
say so.

Many thanks for the response Paul,
after putting "require 'activerecord'" at the top of the super class I
have now a new error message
"{RUBY_HOME}/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require': no such file to load -- activeRecord
(LoadError)"
Do you know how to handle that?
 
L

Logan Capaldo

Many thanks for the response Paul,
after putting "require 'activerecord'" at the top of the super class I
have now a new error message
"{RUBY_HOME}/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require': no such file to load -- activeRecord
(LoadError)"
Do you know how to handle that?
It's require 'active_record' (Note the underscore).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,591
Members
45,102
Latest member
GregoryGri
Top