Created
May 29, 2020 17:09
-
-
Save DanielAmah/43ca2022ae46f764bfd8054bad977591 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## We can leverage on eager loading using joins to load the plans with the subscription in one single query. | |
def index | |
@subscriptions = Subscription.joins(:plan).order(created_at: :desc).page(params[:page]).per(100) | |
end | |
## As a sidenote, I would move the logic for the order into a scope in the Subscription model | |
## Something like this | |
class Subscription < ApplicationRecord | |
scope :latest, -> { order(created_at: :desc) } | |
end | |
## In the controller | |
def index | |
@subscriptions = Subscription.joins(:plan).latest.page(params[:page]).per(100) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment