我可以使用location.doctor_profiles << doctor_profile
将医生添加到地点但是我在尝试向医生添加位置时收到以下错误doctor_profile.locations << location
NameError: undefined local variable or method `doctor_profile' for #<Location>
该关联似乎工作正常,除了这个曾经向doctor_profile添加位置的实例
class DoctorProfile
has_many :doctor_locations
has_many :locations, through: :doctor_locations
class DoctorLocation
belongs_to :doctor_profile
belongs_to :location
class Location
has_many :doctor_locations
has_many :doctor_profiles, through: :doctor_locations
答案 0 :(得分:0)
我仔细检查了导轨ActiveRecord关联指南,您的设置看起来很好。
您是否在数据库中添加了关联的ID?