Can*_*yer 5 ruby ruby-on-rails ruby-on-rails-6
我有一个 Rails5.2.2应用程序,我升级到了6.1.3.2. 我已经设法让除 ActiveStorage 之外的所有内容正常工作。我遇到的问题是我之前在 s3 上保存的图像现在使用相同的代码为 404。当我升级时,rails 创建了以下迁移(也运行了bin/rails app:upgrade):
# This migration comes from active_storage (originally 20190112182829)
class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0]
def up
unless column_exists?(:active_storage_blobs, :service_name)
add_column :active_storage_blobs, :service_name, :string
if configured_service = ActiveStorage::Blob.service.name
ActiveStorage::Blob.unscoped.update_all(service_name: configured_service)
end
change_column :active_storage_blobs, :service_name, :string, null: false
end
end
def down
remove_column :active_storage_blobs, :service_name
end
end
Run Code Online (Sandbox Code Playgroud)
和
# This migration comes from active_storage (originally 20191206030411)
class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0]
def change
create_table :active_storage_variant_records do |t|
t.belongs_to :blob, null: false, index: false
t.string :variation_digest, null: false
t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
end
end
Run Code Online (Sandbox Code Playgroud)
我正在使用此代码来渲染图像:
<%= image_tag(a.file.variant(resize: "100x100"), class: 'p-1') if a.file.variable? %>
Run Code Online (Sandbox Code Playgroud)
我通过ActiveStorage作品上传的任何新图像都通过image_tag. 但是,我之前通过 s 存储的任何文件ActiveStorage 404。
development.rb我也在设置中config.active_storage.service = :amazon。自升级以来此配置未发生变化。