我有以下关系
class Customer < ActiveRecord::Base
has_many :applications, :dependent => :destroy
before_save: validate_presence_priority_id
end
在我的客户控制器中我有
def customer_params
params.require(:customer).permit(:name, application_attributes: [:duration, :priority_id, :_destroy])
end
现在我想做这样的事情
def validate_presence_priority_id((attributes))
if !attributes['priority_id'].present?
attributes.merge!({:_destroy => 1})
end
end
所以基本上我想检查priority_id
是否不存在然后只添加destroy属性。我怎样才能做到这一点?