更新
使用has_and_belongs_to_many
让它工作任何人都知道为什么会这样吗?
您好,
使用有效记录保存时出现以下错误
undefined method `reflect_on_association' for Class:Class
我的关系看起来像这样:
class Contact < ActiveRecord::Base
has_many :classes
has_many :sessions, :through => :classes
end
class Class < ActiveRecord::Base
belongs_to :session
belongs_to :contact
end
class Session < ActiveRecord::Base
has_many :classes
has_many :contacts, :through => :classes
end
我的请求看起来像这样
{"commit"=>"Submit", "contact"=>{"address"=>"", "postcode"=>"", "notes"=>"", "session_ids"=>"2", "phone"=>"", "last_name"=>"w", "email"=>"", "first_name"=>"w"}}
session_id和contact_id应保存在班级模型
中由于
亚历
答案 0 :(得分:3)
马上我会说,因为Class是Ruby中的保留关键字,所以使用:classes作为关联名称是罪魁祸首。反射代码可能试图将关联名称单一化,将“类”作为结果,然后对其进行实例化,获取Class以及那些东西崩溃的地方。