Ruby on rails 检测到使用急切加载[Bulllet Gem]

Ruby on rails 检测到使用急切加载[Bulllet Gem],ruby-on-rails,ruby-on-rails-5,Ruby On Rails,Ruby On Rails 5,我使用的是Rails 5.2.2。我安装了Bullet Gem,并在Bullet.log上获取了以下信息: 根据指南,我在我的account.rb文件中添加了includes:user。我试图将其添加到索引操作和显示操作中,但此警报一次又一次出现 Account.rb: class Account < ApplicationRecord belongs_to :user belongs_to :customer end show.html.erb客户62..64行 <% @

我使用的是Rails 5.2.2。我安装了Bullet Gem,并在Bullet.log上获取了以下信息:

根据指南,我在我的account.rb文件中添加了includes:user。我试图将其添加到索引操作和显示操作中,但此警报一次又一次出现

Account.rb:

class Account < ApplicationRecord
  belongs_to :user
  belongs_to :customer
end
show.html.erb客户62..64行

<% @customer.accounts.each do |ac| %>
   <div class="sl-item">
       <div class="sl-left"> <img src="<%= ac.user.profile_picture %>" alt="user" class="img-circle" /> </div>

如何解决这个问题?

我建议您在html中使用以下内容:

<% @accounts.each do |ac| %>

我建议您在html中使用以下内容:

<% @accounts.each do |ac| %>

您可以再添加一个实例变量,但它会增加controller.action的大小。第二种选择:

# you didn't a add real code where you define @customer, so it just example
@customer = Customer.includes(accounts: :user).find(params[:customer_id])

您可以再添加一个实例变量,但它会增加controller.action的大小。第二种选择:

# you didn't a add real code where you define @customer, so it just example
@customer = Customer.includes(accounts: :user).find(params[:customer_id])

请从views/customers/show.html.erb添加代码。第64行中的错误原因请查看错误stacktrace,因此请添加包含此行的代码块。@Vasilisa感谢我添加到主帖子中。请从views/customers/show.html.erb添加代码。第64行中的错误原因请查看错误stacktrace,因此请添加包含此行的代码块。@Vasilisa感谢我添加到主帖子中。@customer=customer.includeAccounts::user.findparams[:id]这解决了我的问题。谢谢。@customer=customer.includeAccounts::user.findparams[:id]这解决了我的问题。谢谢
# you didn't a add real code where you define @customer, so it just example
@customer = Customer.includes(accounts: :user).find(params[:customer_id])