/ / Rails Error uninitialized constant Assignment :: AssignmentsCourse in Has Many Through Association - ruby-on-rails, ruby, rails-activerecord, has-many-through, nameerror

Rails Error Uninitialized constant Assignment :: AssignmentsCourse in Has Many Through Association - ruby-on-rails, ruby, rails-activerecord, has-many-through, nameerror

Otrzymuję błąd "niezainicjowany stały Assignment :: AssignmentsCourse." Oto moje modele:


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

Odpowiedzi:

3 dla odpowiedzi № 1
has_many :assignmentsCourses

To i wszystkie twoje pola nie powinny być wielbłądamicased nie jest w stylu ruby ​​i przerywa ładowanie klasy. Koniec powinien być także pluralizowany, a nie oba słowa. Za kulisami activerecord depluralizuje podany symbol i ładuje klasę podobną do tej require. Jeśli próbowałeś require "activeRecord" to nie działa na przykład. Ruby używa podkreśleń do wyprowadzania nazw klas wielu słów.

Powinno być: has_many :assignment_courses

Zmień też ma wiele. Twoi akcesorzy nie powinni być wielbłądami albo ruby_style_is_to_underscore.