我在使用.user_ids
我的通信模型如下所示:
class communication
has_many :recipients
has_many :users, :through => :recipients
end
在我为通信控制器创建操作中,我试图手动添加user_ids
到通信对象,如下所示:
@communication = new Communications(params[:communication])
@communication.user_ids << id
logger.debug @communication.user_ids # is empty
我无法弄清楚为什么@communication.user_ids
数组是空的,即使我像这样进行硬编码 id :
@communication = new Communications(params[:communication])
@communication.user_ids << 1
logger.debug @communication.user_ids # is still empty!
我仍然得到一个空@communication.user_ids
数组。
我的方法是否遗漏了什么?有什么技巧可以让它工作吗?
提前致谢!