Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass parameters to ActiveModel serializer

I'm using active model serializer. I have a model event which has_many activities.

I want to return the event with the first n activities. I think I should pass the params n to the event serializer.

like image 551
Bruce Xinda Lin Avatar asked Apr 28 '14 17:04

Bruce Xinda Lin


1 Answers

In version ~> 0.10.0 you need to use @instance_options. Using @Jon Gold example from above:

# controller def action   render json: @model, option_name: value end  # serializer class ModelSerializer::ActiveModel::Serializer   def some_method     puts @instance_options[:option_name]   end end 
like image 125
Eric Norcross Avatar answered Sep 22 '22 20:09

Eric Norcross