更改活动模型序列化器默认适配器 [英] Changing Active Model Serializers Default Adapter

查看:126
本文介绍了更改活动模型序列化器默认适配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想从默认属性适配器切换到json api适配器,我应该在哪里做?

If I want to switch from the default attributes adapter to the json api adapter, where would I do this?

入门说明:

通常来说,作为AMS的用户,您将编写(或生成)这些序列化程序类.如果要使用其他适配器,例如JsonApi,则可以在初始化程序中对其进行更改:

ActiveModel::Serializer.config.adapter = :json_api

他们指的是什么初始值设定项?我要创建一个新的吗?抱歉,菜鸟问题

What initializer are they referring to? Do I create a new one? Sorry for the noob question

推荐答案

通常,将初始化程序放置在Rails应用程序的app/config/initializers目录下.

In general, initilizers are put under the app/config/initializers directory in a Rails app.

因此,在您的情况下,您可以在其中创建一个新文件:ams.rb并将这些内容放在该文件中:

So, in your case, you can create a new file there: ams.rb and put those content in that file:

# app/config/initializers/ams.rb    
ActiveModel::Serializer.config.adapter = :json_api

此外,请参见 github问题.

如果要使用:json_api格式,则必须使用Github的0.10.0分支.

If you want to be using the :json_api format, you have to use the 0.10.0 branch off of Github.

这篇关于更改活动模型序列化器默认适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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