Created
September 14, 2018 10:54
-
-
Save tonyfg/28b225a55128c2a9bcae959292192a7b to your computer and use it in GitHub Desktop.
Org list #index optimized with .includes
This file contains 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
# old action | |
def index | |
@organizations = Organization.all | |
end | |
# new action | |
def index | |
@organizations = if request.format.html? | |
Organization.includes(hqs: :country).all | |
else | |
Organization.includes(hqs: [:country, :stores]).all | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment