如何将参数传递给 ActiveModel 序列化程序 [英] How to pass parameters to ActiveModel serializer

查看:33
本文介绍了如何将参数传递给 ActiveModel 序列化程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 活动模型序列化程序.我有一个模型事件,它有_许多活动.

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

我想用前 n 个活动返回该事件.我想我应该将参数 n 传递给事件序列化程序.

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

推荐答案

传入的选项可通过 @options 哈希获得.所以如果你这样做:

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

respond_with @event, activity_count: 5

您可以在序列化程序中使用 @options[:activity_count].

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

这篇关于如何将参数传递给 ActiveModel 序列化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆