Search code examples
ruby-on-railsactive-model-serializers

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.


Solution

  • Options passed in are available through the @options hash. So if you do:

    respond_with @event, activity_count: 5
    

    You can use @options[:activity_count] within the serializer.