【发布时间】:2018-11-30 21:36:40
【问题描述】:
给定
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 和active_storage_blobs 进行 N+1 次查询?
【问题讨论】:
标签: ruby-on-rails rails-activestorage select-n-plus-1