ruby on rails - How to pass multiple models to ActiveSerializer -
my rails controller action looks trivial following:
def show @batter_rankings = dfshittersbeta.all @pitcher_rankings = dfsspbeta.all render :json => ?? end in case, both collections above each have own serializer. want have them part of 1 api. api like:
{'pitchers' => [@pitcher_rankings], 'hitters' => [@hitter_rankings] }
i'm not entirely sure how pass both models render json each own serializer though , perhaps global serializer allows me specify how final output looks.
you can include both pitchers , hitters in json response this:
render json: {pitchers: @pitcher_rankings, hitters: @hitter_rankings}
Comments
Post a Comment