给定
class User < ApplicationRecord
has_one_attached :avatar
def avatar_path
Rails.application.routes.url_helpers.rails_blob_path avatar,
disposition: 'inline',
only_path: true
end
end
class UsersController < ApplicationController
def index
@users = User.all
end
end
如何在尝试显示每个头像时active_storage_attachments
避免N+1 次查询?active_storage_blobs