Search code examples
ruby-on-railsrubyrails-activestorage

How do I update an ActiveStorage blob in rails?


I have a file attached to a variable (@template) with the following blob:

#<ActiveStorage::Blob id: 581175, key: "0gm1oho37jwqlg4vdhhhabmhmbbs", filename: "open-uri20200122-24977-1gwql8e", content_type: "image/png", metadata: {"identified"=>true}, byte_size: 1651505, checksum: "U+Cj40eyRxQUBJWD1k6MBg==", created_at: "2020-01-22 17:45:49">

I need to update the metadata from {"identified"=>true} to {"identified"=>true, "height"=> "300px", "width"=>"200px"}

How do I do it?


Solution

  • Just execute

    ActiveStorage::Blob.find(581175).update(metadata: {"identified"=>true, "height"=> "300px", "width"=>"200px"})
    

    That's it.