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

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

问题描述

如果我想从默认属性适配器切换到 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天全站免登陆