Skip to content

Instantly share code, notes, and snippets.

@bogdanRada
Forked from mihaic195/blob_observer.rb
Created February 25, 2022 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bogdanRada/640dba20154ca5ff7a7e2f9d2ef2b0a4 to your computer and use it in GitHub Desktop.
Save bogdanRada/640dba20154ca5ff7a7e2f9d2ef2b0a4 to your computer and use it in GitHub Desktop.
Blob observer
class BlobObserver < ActiveRecord::Observer
observe ActiveStorage::Blob
def after_save(blob)
blob.update_columns(storage_url: "https://s3-#{ENV['AWS_AS_S3_REGION']}.amazonaws.com/#{ENV['AWS_AS_S3_BUCKET']}/" + blob.key)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment