从接触控制器具有内部编辑的动作...ActiveRecord的铲运营商<<
@programs << @contact.program
将会产生以下错误:
NoMethodError - undefined method `<<' for Program::ActiveRecord_Relation
联系型号:
belongs_to :program
程序模式:
has_many :contacts
validates :name, presence: true, uniqueness: true
@programs.class
Program::ActiveRecord_Relation
@contact.program.class
Program(id: integer, name: string, active: boolean, created_at: datetime, updated_at: datetime)
问:为什么此操作失败?为什么不能将记录添加到记录集合中。什么是阻止收集(ActiveRecord_Relation)添加记录?
我需要添加联系人的程序来编程,这全是 – user6337901
'程序'不'has_many:程序'。如果你想简单地坚持“联系人的程序”,只需调用'.save'就可以了。 – coreyward