Forum: Ruby on Rails would you help about const_missing 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.
171318bdeab893a9363d924bad0cfb9f?d=identicon&s=25 dev.mykey (Guest)
on 2008-10-10 12:24
(Received via mailing list)
Hello.

I have made a model name is User, so have created "users" table.
and I made Customer class inhrtied by User Class.

When I call the Customer class in some controller, the controller
passed error msg to me.

It seems that controller doesn't find table("users")  when make
Customer instance.

previously, thanks for your help.

error message -----------------------------

NameError in MemberController#signup
uninitialized constant MemberController::Customer

RAILS_ROOT: C:/Documents and Settings/Administrator/My Documents/
Aptana Studio/pseudo

c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:493:in `const_missing' app/controllers/
member_controller.rb:9:in `signup'-e:2:in `load'-e:2

here is pieces of controller and model code

----------------------- controller --------------------------------
class MemberController < ApplicationController

  def signup
    if request.post?
      @member = Customer.new(params[:user])
      if @member.save

      end
    end
  end

-------------------------- model ------------------------------------
class User < ActiveRecord::Base

end

class Customer < User
  def initailize
    self.type = 'Customer'
  end
end

class Manager < Employee
  def initailize
    self.type = 'Manager'
  end
---------------------------------------------------------------------------

my application’s environment


Ruby version 1.8.6 (i386-mswin32)
RubyGems version 1.3.0
Rails version 2.1.1
Active Record version 2.1.1
Action Pack version 2.1.1
Active Resource version 2.1.1
Action Mailer version 2.1.1
Active Support version 2.1.1
Application root C:/Documents and Settings/Administrator/My Documents/
Aptana Studio/pseudo
Environment development
Database adapter mysql
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-10 12:28
(Received via mailing list)
On Oct 10, 10:17 am, "dev.mykey" <dev.my...@gmail.com> wrote:
> Hello.
>
> I have made a model name is User, so have created "users" table.
> and I made Customer class inhrtied by User Class.
>
> When I call the Customer class in some controller, the controller
> passed error msg to me.
>
> It seems that controller doesn't find table("users")  when make
> Customer instance.

No, it's not finding your customer class because it's not in
customer.rb.
Either put Customer in customer.rb or require user with
require_dependency

ALso you don't need that initializer to set the type column (rails
will do that for you). It's also not how initialize is spelled.
Fred
This topic is locked and can not be replied to.