Ruby on rails 未初始化常数
我有两个班,学生和监护人。第三类护生负责管理学生和监护人之间的关系。下面给出了这些类的快照:Ruby on rails 未初始化常数,ruby-on-rails,ruby,ruby-on-rails-2,Ruby On Rails,Ruby,Ruby On Rails 2,我有两个班,学生和监护人。第三类护生负责管理学生和监护人之间的关系。下面给出了这些类的快照: class Student < ActiveRecord::Base has_one :stud_guards, :foreign_key => 'student_id', :dependent=>:destroy end class Guardian < ActiveRecord::Base has_many :stud_guards, :depen
class Student < ActiveRecord::Base
has_one :stud_guards, :foreign_key => 'student_id', :dependent=>:destroy
end
class Guardian < ActiveRecord::Base
has_many :stud_guards, :dependent=>:destroy
end
class StudGuard < ActiveRecord::Base
belongs_to :student_id, :class_name => 'Student'
belongs_to :guardian_id, :class_name => 'Guardian'
end
class-Student'student\u id',:dependent=>:destroy
结束
类监护人:destroy
结束
类StudGuard'student'
属于:监护人id,:class\u name=>“监护人”
结束
在代码中,如果我执行@guardian.stud\u guards(其中@guardian包含有效的监护人项目),我就能够获得stud\u guards条目数组。但是,如果我执行@student.stud_guards(其中@student有一个有效的学生项),我会得到一个错误“uninitialized constant student::StudGuards”。我似乎无法理解我在这里遗漏了什么。has#u one
应采用单数形式的型号名称
如果您编写的有一个:stud\u guards
,那么它正在寻找一个名为StudGuards
的模型,该模型不存在,您得到了错误。使用#has_one
,Rails不会对关联名称stud_guards
应用方法,但是
如果您注意到“uninitialized constant Student::StudGuards”,那么很明显Rails会搜索模型StudGuards
,正如我从:stud\u guards
中所说的那样。但是如果您编写stud\u-guard
,它将得到您定义的StudGuard
希望现在就清楚了。#has#u one
应采用单数形式的型号名称
如果您编写的有一个:stud\u guards
,那么它正在寻找一个名为StudGuards
的模型,该模型不存在,您得到了错误。使用#has_one
,Rails不会对关联名称stud_guards
应用方法,但是
如果您注意到“uninitialized constant Student::StudGuards”,那么很明显Rails会搜索模型StudGuards
,正如我从:stud\u guards
中所说的那样。但是如果您编写stud\u-guard
,它将得到您定义的StudGuard
希望现在就清楚了。#has#u one
应采用单数形式的型号名称
如果您编写的有一个:stud\u guards
,那么它正在寻找一个名为StudGuards
的模型,该模型不存在,您得到了错误。使用#has_one
,Rails不会对关联名称stud_guards
应用方法,但是
如果您注意到“uninitialized constant Student::StudGuards”,那么很明显Rails会搜索模型StudGuards
,正如我从:stud\u guards
中所说的那样。但是如果您编写stud\u-guard
,它将得到您定义的StudGuard
希望现在就清楚了。#has#u one
应采用单数形式的型号名称
如果您编写的有一个:stud\u guards
,那么它正在寻找一个名为StudGuards
的模型,该模型不存在,您得到了错误。使用#has_one
,Rails不会对关联名称stud_guards
应用方法,但是
如果您注意到“uninitialized constant Student::StudGuards”,那么很明显Rails会搜索模型StudGuards
,正如我从:stud\u guards
中所说的那样。但是如果您编写stud\u-guard
,它将得到您定义的StudGuard
希望它现在能清除。试试这个:
class Student < ActiveRecord::Base
has_one :stud_guard, :foreign_key => 'student_id', :dependent=>:destroy
end
class Guardian < ActiveRecord::Base
has_many :stud_guards, :dependent=>:destroy
end
class StudGuard < ActiveRecord::Base
belongs_to :student_id, :class_name => 'Student'
belongs_to :guardian_id, :class_name => 'Guardian'
end
试试这个:
class Student < ActiveRecord::Base
has_one :stud_guard, :foreign_key => 'student_id', :dependent=>:destroy
end
class Guardian < ActiveRecord::Base
has_many :stud_guards, :dependent=>:destroy
end
class StudGuard < ActiveRecord::Base
belongs_to :student_id, :class_name => 'Student'
belongs_to :guardian_id, :class_name => 'Guardian'
end
试试这个:
class Student < ActiveRecord::Base
has_one :stud_guard, :foreign_key => 'student_id', :dependent=>:destroy
end
class Guardian < ActiveRecord::Base
has_many :stud_guards, :dependent=>:destroy
end
class StudGuard < ActiveRecord::Base
belongs_to :student_id, :class_name => 'Student'
belongs_to :guardian_id, :class_name => 'Guardian'
end
试试这个:
class Student < ActiveRecord::Base
has_one :stud_guard, :foreign_key => 'student_id', :dependent=>:destroy
end
class Guardian < ActiveRecord::Base
has_many :stud_guards, :dependent=>:destroy
end
class StudGuard < ActiveRecord::Base
belongs_to :student_id, :class_name => 'Student'
belongs_to :guardian_id, :class_name => 'Guardian'
end
您是否尝试过删除
外键
?正常。你在做@student。当你有时,stud\u守卫有一个关系。那么试试@student.stud\u-guard
你有没有试过取下外键
?好的。你在做@student。当你有时,stud\u守卫有一个关系。那么试试@student.stud\u-guard
你有没有试过取下外键
?好的。你在做@student。当你有时,stud\u守卫有一个关系。那么试试@student.stud\u-guard
你有没有试过取下外键
?好的。你在做@student。当你有时,stud\u守卫有一个关系。所以试试@student.stud\u-guard