ruby-on-rails – Ruby on Rails NameError:未初始化的常量

我只是建立了一个新的迁移和模型关系,并在测试表之间的关系时在控制台中我得到以下错误:NameError:uninitialized constant.

有谁知道什么是错的?

谢谢

编辑:

这是错误

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

ProfileNotification迁移中的代码

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

解决方法

好吧,我弄明白了这个问题.当我运行ruby脚本/生成模型时,我正在键入ruby脚本/生成模型ProfileNotifications.当我输入ruby脚本/生成模型ProfileNotification(单数)时,它工作.命名约定会杀了我.谢谢你的帮助.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...