我有(合同和附件与has_and_belongs_to_many相关联):
# Get the contract and specific accessory based on params @contract = Contract.find(params[:id]) @accessory = @contract.accessories.find(params[:accessory_id])
现在,我想从@contract中删除该特定的附件.我不想从DB中删除记录,而只是想删除两者之间的关联.
这样做的好办法是什么?
谢谢!
解决方法
这个怎么样:
@contract.accessories.delete(@accessory)
参见:(Rails,Associations) How do I remove a single HABTM associated item?