Ruby on rails 未定义的方法`relationship\u delegate\u class';
我有三种型号:Ruby on rails 未定义的方法`relationship\u delegate\u class';,ruby-on-rails,Ruby On Rails,我有三种型号: class Course < ApplicationRecord has_many :sections end class Section < ApplicationRecord belongs_to :course has_many :section_files end class SectionFile < ApplicationRecord belongs_to :section end 课程
class Course < ApplicationRecord
has_many :sections
end
class Section < ApplicationRecord
belongs_to :course
has_many :section_files
end
class SectionFile < ApplicationRecord
belongs_to :section
end
课程
每当我试图调用@course.sections
时,我都会收到错误course::Section:Module的未定义方法“relation\u delegate\u class”
有什么想法吗?修复了我在节中指定类名的问题
Class Course < ApplicationRecord
has_many :sections, class_name: "::Section"
end
课程
虽然,@section.section\u文件
似乎可以工作,而无需明确说明类名很好,谢谢!我有完全相同的错误情况,所有模型都是全局的(模块之外),都是从ApplicationRecord派生的,出于某种原因,只有一个关系不起作用。你找到这个问题的原因了吗?我很高兴应用修复程序,但我更愿意理解为什么这里需要它。