app/controllers/digital_assets_controller.rb in daengine-0.6.22 vs app/controllers/digital_assets_controller.rb in daengine-0.6.23
- old
+ new
@@ -27,11 +27,24 @@
respond_with(@digital_asset)
end
def update
da_passed = params[:digital_asset]
- da = DigitalAsset.find_or_initialize_by(digital_asset_id: da_passed[:digital_asset_id])
+ digital_asset_id = params[:id] || da_passed[:digital_asset_id]
+ assets = DigitalAsset.any_of({digital_asset_id: digital_asset_id}, {path: da_passed[:path]})
+ case assets.count
+ when 0 #creating
+ da = assets.build
+ da.digital_asset_id = digital_asset_id
+ when 1 # updating single
+ da = assets.first
+ else #duplicate path / id combo
+ assets.delete_all
+ da = DigitalAsset.find_or_initialize_by(digital_asset_id: digital_asset_id)
+ end
creating = da.new?
+ # da_passed.delete(:digital_asset_id) # remove the ID from params hash
+ da_passed[:digital_asset_id] = digital_asset_id # the url ID wins
da.update_attributes! da_passed
if(creating)
head :created, location: digital_asset_path(da)
else
head :ok