Replace an asset's file
If you need to replace the file of an existing attachment without changing the URL, follow these steps:
Copy the new file from your computer to a
scp filename.ext <hostname>:/tmp/filename.ext
Find the asset:
asset = Asset.find("asset-id-from-url")` # e.g. `57a9c52b40f0b608a700000a` # or for a Whitehall asset: asset = WhitehallAsset.find_by(legacy_url_path: '/government/uploads/system/uploads/attachment_data/file/id/path.ext')`
Check the asset is what you think it is.
Replace the file:
asset.file = Pathname.new("/tmp/filename.ext").open asset.save!