How to eager load associations with the current_user?

前端 未结 4 765
暖寄归人
暖寄归人 2021-02-07 05:33

I\'m using Devise for authentication in my Rails app. I\'d like to eager load some of a users associated models in some of my controllers. Something like this:

c         


        
4条回答
  •  囚心锁ツ
    2021-02-07 05:52

    Why not do it with default_scope on the model?

    like so:

    Class User  < ActiveRecord::Base
      ...
      default_scope includes(:saved_listings)
      ...
    end
    

提交回复
热议问题