0

我收到错误“未初始化的常量 Assignment::AssignmentsCourse”。这是我的模型:


赋值.rb

class Assignment < ActiveRecord::Base
    has_many :assignmentsCourses
    has_many :courses, :through => :assignmentsCourses
    attr_accessible :name, :dateAssigned, :dateDue, :description, :weight, :category_tokens
    attr_reader :category_tokens

    def category_tokens=(ids)
        puts 'el ids: ', ids.split(",")
        self.courseIds = ids.split(",")
    end
end

课程.rb

class Course < ActiveRecord::Base
    has_and_belongs_to_many :assignments
end

作业课程.rb

class AssignmentCourse < ActiveRecord::Base
    belongs_to :assignment
    belongs_to :course
    attr_accessible :assignment_id, :course_id
end
4

1 回答 1

3
has_many :assignmentsCourses

这和你所有的字段都不应该是驼峰式的,它不是红宝石风格,它会破坏类加载。结尾也只能是复数形式,而不是两个词。在幕后 activerecord 使您提供的符号去复数,并进行类似于require. 例如,如果您尝试过require 'activeRecord',那将无法正常工作。Ruby 使用下划线来派生多词类名。

它应该是: has_many :assignment_courses

改变也有很多。ruby_style_is_to_underscore 的访问器不应该是驼峰式的。

于 2012-01-29T03:06:41.533 回答