Questions tagged [active-model-serializers]

The purpose of `ActiveModel::Serializers` is to provide an object to encapsulate serialization of `ActiveModel` objects, including `ActiveRecord` objects.

Purpose

The purpose of ActiveModel::Serializers is to provide an object to encapsulate serialization of ActiveModel objects, including ActiveRecord objects.

Serializers know about both a model and the current_user, so you can customize serialization based upon whether a user is authorized to see the content.

In short, serializers replaces hash-driven development with object-oriented development.

Documentation

See the github project's README

739 questions
0
votes
1 answer

Use alternate association id for ActiveModel::Serializer association

I have an app where there I have normal ActiveRecord ids as well as a unique field (e.g. ident) that's unique on an external, canonical database. A model looks like: class Parent has_many :childs, foreign_key: :parent_ident, primary_key:…
GSP
  • 3,763
  • 3
  • 32
  • 54
0
votes
1 answer

How can I assign the results of a Rails "render json:" and "render_with" to a variable, for storage in a table?

I have some code rendering json as follows... serialized = ActiveModel::ArraySerializer.new(actions, each_serializer: Api::V1::ActionSerializer) render json: { actions: serialized } What I need... is to turn serialized into a string…
chris P
  • 6,359
  • 11
  • 40
  • 84
0
votes
1 answer

Active Model Serializer relations return only ids on production but full object on dev

I'm having an issue with a discrepancy between what is happening on the live vs dev environment of my ruby on rails API. On development I see the full object returned in the JSON result, however, on the production server we only get ids back. I…
paviktherin
  • 121
  • 2
  • 9
0
votes
1 answer

Rails Active Model Serializers conflict with Ajax?

When I use gem "active_model_serializers", my all Ajax can't work, my code like following: $(document).on('change','#brand_id_dropdown', function () { var request = "/beacons/find_beacon_uuid_given_brand_id?brand_id=" +…
John
  • 387
  • 5
  • 17
0
votes
1 answer

Ember Data EmbeddedRecordsMixin won't save newly created records

I'm using Ember Data 1.13.7 and Ember 1.13.6 with ActiveModelSerializer and EmbeddedRecordsMixin. I have 2 models: // models/post.js export default DS.Model.extend({ //bunch of attrs commentStuff: DS.belongsTo('commentStuff',…
Confused
  • 176
  • 3
  • 15
0
votes
1 answer

Serializing model with multiple primary keys

I have a Rails API that communicates with an Ember app. I need to be able to serialize a model that has two primary keys instead of the default id. This is what it looks like right now: Models # This is the problem model: class Value <…
0
votes
1 answer

ActiveModel serializers json api format deserializition

i'm using AMS version 0.10.0.rc2. it support json api format. it's ok. but i wanna deserialize request data (json api formatted) to activerecord model. any idea?
Brain
  • 69
  • 1
  • 2
  • 6
0
votes
1 answer

Object has many objects has many objects in active_model_serializers

Banging my head against the wall for these 2 days to figure out how to display object has many objects has many objects in active_model_serializers. Here is my serializers : Section serializer : class SectionSerializer < ActiveModel::Serializer …
Ardian
  • 155
  • 2
  • 11
0
votes
1 answer

User ActiveModel Serializer json_api adapter

I am working to return json response with format following the guide from http://jsonapi.org using AMS. however default AMS adapter does not support this. I try to enable the ActiveModel::Serializer::Adapter::JsonApi suggested here:…
channa ly
  • 9,479
  • 14
  • 53
  • 86
0
votes
1 answer

how to return an array of serialized objects via Active Model Serializer

I have a user who has a list of liked items. I'd like to create a serializer that returns this. For a single items, I would have something like this: class UserProfileSerializer < ActiveModel::Serializer attributes :id, :name, :liked_items2 def…
timpone
  • 19,235
  • 36
  • 121
  • 211
0
votes
1 answer

Getting the active_model_serializer for model

I am trying to send multiple different objects over a generic request - more specificly - I have different types of users, with different model, all might be return when creating a new session. looking at rail casts #409 - ryan calls…
0
votes
1 answer

Is it possible to redefine {object} within a serializer?

I have users and I have admins, but an admin just references a user. Within the admin, I have admin_roles and each admin_role has many admins. In my AdminRoleSerializer, I have a has_many admins that gets serialized into the AdminRoleUserSerializer…
Dan
  • 1,238
  • 2
  • 17
  • 32
0
votes
2 answers

ActiveModel::Serializer not working

I have a Client model and a method in my controller that should return the nearest clients. I'm using ActiveModel::Serializers but it's not working. class ClientSerializer < ActiveModel::Serializer attributes :id, :name, :path, :url def url …
0
votes
2 answers

How to specify a different root name for the embedded objects?

In my app I had BlogPost model and User model that are related through relation named author. To serve data from my Rails app I use active_model_serializers with definition: class Blog::PostSerializer < ActiveModel::Serializer embed :ids, include:…
Hauleth
  • 22,873
  • 4
  • 61
  • 112
0
votes
2 answers

How can I link to multiple different tables with one id column in Rails?

I have a table that stores in-app purchases. Model name is Item. It stores some thing like price, description, etc. Now, there are a few different Item types. There are Themes and Settings. A theme example would be like Night Theme which changes the…
chris P
  • 6,359
  • 11
  • 40
  • 84