Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Active Model Serializers Default Adapter

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

The getting started states this:

Generally speaking, you as a user of AMS will write (or generate) these serializer classes. If you want to use a different adapter, such as a JSON API, you can change this in an initializer:

ActiveModel::Serializer.config.adapter = :json_api

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

like image 385
Jshoe523 Avatar asked Nov 10 '15 00:11

Jshoe523


2 Answers

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

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

Also, see this github issue.

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

like image 54
K M Rakibul Islam Avatar answered Oct 22 '22 05:10

K M Rakibul Islam


For newer version of AMS put this to config/initializers/ams.rb:

require 'active_model_serializers'

ActiveModelSerializers.config.adapter = :json_api
like image 45
EugZol Avatar answered Oct 22 '22 04:10

EugZol