-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to pass outside variables into the serializer? #1278
Comments
Could you be more specific? |
Removing some code for brevity but this is the gist of it. I can't do the method call within the serializer because I'd be doing multiple DB hits for it, so I collect all the results and call the hash within the serializer. Controller def index
@games = Game.games
# returns a hash
@temp_players = GameQueue.players(params[:input])
render json: @games, include: [:perimeters, :start_zones]
end Serializer class GameSerializer < ActiveModel::Serializer
attributes :id, :name, :max_players, :description, :level, :best_finish
attribute :buy_in_price, key: :buy_in_price_dollars
has_many :perimeters, serializer: PerimeterSerializer
has_many :start_zones, serializer: StartZoneSerializer
def best_finish
if @players
@players[object.id]
end
end
end |
what's the variable you're trying to pass in? Check out In the past, I've created an attr_accessor on my model and used that to On Mon, Oct 19, 2015 at 8:09 PM, Damian Mastylo [email protected]
|
@dmastylo You could add |
Thanks that works! @beauby |
I have a collection that, in order to save db trips, uses a second collection that has some data associated to the records in the first collection. In RABL I could simply reference the global variable
@data
inside the view template and be done. Is this doable with AMS?The text was updated successfully, but these errors were encountered: