###前提・実現したいこと
bulletを使ってN+1問題を直しています。
直していく中で、ActivityページのN+1問題でどのように直したらいいかわからなくって困っています。どのようにしたらいいでしょうか
###発生している問題
GET /activities USE eager loading detected Comment => [:message] Add to your finder: :includes => [:message]
###該当のソースコード
activities_controller
def index @activities = PublicActivity::Activity.includes(:owner, :trackable).order("created_at DESC").where(owner_id: current_user.following_ids, owner_type: "User").page(params[:page]).per(30) end
_create.html(comment)
added comment <% if activity.trackable %> to <%= link_to activity.trackable.message.title, activity.trackable.message %> <% else %> which has since been removed <% end %>
activities/index.html
<% @activities.each do |activity| %> <div class="activity"> <%= activity.created_at %> <%= link_to activity.owner.username, activity.owner if activity.owner %> <%= render_activity activity %> </div> <% end %>
comment.rb
class Comment < ApplicationRecord include PublicActivity::Common belongs_to :message belongs_to :user end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/02 08:46
2017/06/02 10:08
2017/06/03 18:39