Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails NameError: uninitialized constant

I just set up a new migration and model relationships, and in console when testing the relationship between tables I get the following error: NameError: uninitialized constant.

Does anyone have any idea what is wrong?

Thank you

Edit:

Here's the error

NameError: uninitialized constant Profile::ProfileNotification
  from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:105:in `const_missing'
  from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2199:in `compute_type'
  from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
  from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2195:in `compute_type'
  from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/reflection.rb:156:in `send'
  from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/reflection.rb:156:in `klass'
  from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/reflection.rb:187:in `quoted_table_name'
  from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/has_many_association.rb:97:in `construct_sql'
  from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/association_collection.rb:21:in `initialize'
  from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations.rb:1300:in `new'
  from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations.rb:1300:in `profile_notifications'
  from (irb):3

Code from the ProfileNotification migration:

class CreateProfileNotifications < ActiveRecord::Migration
  def self.up
    create_table :profile_notifications do |t|
      t.integer :profile_id, :null => false
      t.integer :notification_id, :null => false
      t.string :notification_text
      t.boolean :checked, :default => false
      t.boolean :update_reply, :default => false
      t.boolean :opinion_reply, :default => false
      t.boolean :message_reply, :default => false
      t.boolean :pm, :default => false
      t.boolean :accepted_friend, :default => false
      t.boolean :accepted_supporter, :default => false
      t.timestamps
    end
  end

  def self.down
    drop_table :profile_notifications
  end
end
like image 702
Brian Avatar asked Nov 30 '10 03:11

Brian


People also ask

What does uninitialized constant mean in Ruby?

Ruby NameError Uninitialized Constant Causes You'll see this error when the code refers to a class or module that it can't find, often because the code doesn't include require, which instructs the Ruby file to load the class.

What is a name error in Ruby?

NameError is raised when you reference a constant or a variable which isn't defined in the current context. A ruby constant can be a Module, Class, or a CONSTANT_VARIABLE, and must always start with an upper case letter.


1 Answers

Well, I figured out the problem. When I was running ruby script/generate model, I was typing ruby script/generate model ProfileNotifications. When I typed ruby script/generate model ProfileNotification (singular) it worked. Naming conventions kill me. Thanks for all the help.

like image 149
Brian Avatar answered Oct 02 '22 22:10

Brian