Last active
December 16, 2015 18:17
-
-
Save philsturgeon/60aafc8787fe008fddf1 to your computer and use it in GitHub Desktop.
Using AMS? Whitelist includes to avoid overuse and n+1 slowness
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
# Somewhere, maybe in ApplicationController | |
def whitelist_relationships(params) | |
whitelist = %w(driver seats driver.avatar) | |
params[:include].split(/,/) & whitelist if params[:include].present? | |
end | |
# Then when rendering the resource | |
render json: Array(@resources), root: :trips, include: whitelist_relationships(params) |
nhocki
commented
Dec 16, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment