Rails错误未初始化的常量Assignment :: AssignmentsCourse in Many With Through Association

时间:2022-09-29 05:28:22

I'm getting the error "uninitialized constant Assignment::AssignmentsCourse". Here are my models:

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


assignment.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

course.rb

class Course < ActiveRecord::Base
    has_and_belongs_to_many :assignments
end

AssignmentCourse.rb

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

1 个解决方案

#1


3  

has_many :assignmentsCourses

This and all of your fields should not be camel cased it is not ruby style and it breaks the class loading. The end should only be pluralized too, not both words. Behind the scenes activerecord depluralizes the symbol you provide and does class loading similar to require. If you tried require 'activeRecord' that would not work for example. Ruby uses underscores to derive multi word class names.

这个和你的所有字段都不应该是驼色的,它不是ruby风格,它打破了类加载。结尾也应该只是多元化,而不是两个词。在幕后,activerecord会对您提供的符号进行省略,并且类加载类似于require。如果您尝试过要求'activeRecord',那将不起作用。 Ruby使用下划线来派生多个单词类名。

It should be: has_many :assignment_courses

它应该是:has_many:assignment_courses

Change the has many though too. Your accessors should not be camel cased either ruby_style_is_to_underscore.

改变也有很多。你的访问者不应该是驼色的ruby_style_is_to_underscore。

#1


3  

has_many :assignmentsCourses

This and all of your fields should not be camel cased it is not ruby style and it breaks the class loading. The end should only be pluralized too, not both words. Behind the scenes activerecord depluralizes the symbol you provide and does class loading similar to require. If you tried require 'activeRecord' that would not work for example. Ruby uses underscores to derive multi word class names.

这个和你的所有字段都不应该是驼色的,它不是ruby风格,它打破了类加载。结尾也应该只是多元化,而不是两个词。在幕后,activerecord会对您提供的符号进行省略,并且类加载类似于require。如果您尝试过要求'activeRecord',那将不起作用。 Ruby使用下划线来派生多个单词类名。

It should be: has_many :assignment_courses

它应该是:has_many:assignment_courses

Change the has many though too. Your accessors should not be camel cased either ruby_style_is_to_underscore.

改变也有很多。你的访问者不应该是驼色的ruby_style_is_to_underscore。