Home > Software design >  ActiveStorage Blobs table, possible to ignore column?
ActiveStorage Blobs table, possible to ignore column?

Time:11-06

I'm doing a Rails 6.1 upgrade at the moment and wondering if there's a way to set the new service_name column to be ignored. I know how to do this with an ActiveRecord table, but not a Rails' internal table (not sure what to call it).

So above details aside, how does one set a column in the active_storage_blobs table to be ignored?

CodePudding user response:

# app/initializers/active_storage_service_name_backport.rb
if Gem::Version.new(Rails.version) >= Gem::Version.new("6.1")
  raise "This monkey patch is only needed before Rails 6.1. Your version is #{Rails.version}. Please delete #{__FILE__}."
end

ActiveStorage::Blob.tap do |klass|
  klass.ignored_columns = klass.ignored_columns.dup.push(:service_name)
end

CodePudding user response:

# app/initializers/active_storage_ignore_service_name_backport.rb

module ActiveStorageIgnoreServiceNameBackport
  extend ActiveSupport::Concern

  included do
    ignored_columns = [:service_name]
  end
end

Rails.configuration.to_prepare do
  ActiveStorage::Blob.include(ActiveStorageIgnoreServiceNameBackport)
end
  • Related