내가 않는 이유는 모델의 몇has_and_belongs_to_many가 인스턴스 메소드가 아닌 클래스 메소드를 추가하는 이유는 무엇입니까? 이 추가되어야하는 동안
class Product < ActiveRecord::Base
has_and_belongs_to_many :categories
end
지금
class Category < ActiveRecord::Base
has_and_belongs_to_many :products
end
왜 내가
prod = Product.new
prod.categories << Category.new
을 말할 수있다 has_and_belongs_to_many
Product#categories<<
같은 클래스 메소드를 추가 인스턴스 메서드?
어떻게 이러한 클래스 메서드를 사용하여 연결을 설정할 수 있습니까?
. 왜 그렇지 않다고 생각하니? 당신은 예를 협회로 액세스 할 때이 http://apidock.com/rails/ActiveRecord/Associations/ClassMethods/has_and_belongs_to_many – michelpm
는 오류 메시지를 받고 있습니까? 번호 – nik7
에 따라 – lurker