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

Ember.js route for the current user's /settings page

A common pattern for a user's settings page would be for it to live at /settings. In my Rails app, I'm accomplishing this on the API side by mapping get 'settings' to Settings#show and looking for the current_user's settings. But on the Ember side,…
0
votes
1 answer

ActiveModelSerializer / EmberJS. Many-to-many relationship. Do I need a join model in Rails back-end?

Posts have many tags and Tags have many posts. In Rails, I'll typically need to make a Post_Tags model and migration to join the two models. Using an EmberJS front-end, I'm not sure how to do the serializers and if a Post_Tags model is…
0
votes
1 answer

Can't access ActiveModel::Serialized attribute from views

Trying to fetch some products from this API - but I can't seem to access my ActiveModel::Serialized attribute product.name from my views. Where did I go wrong? Model: require 'rest_client' class ThirdPartyProducts include…
Mark Boulder
  • 13,577
  • 12
  • 48
  • 78
0
votes
1 answer

Specify only needed JSON keys as ActiveModel::Serializers attributes

When parsing a JSON API using ActiveModel::Serializers, is there a way not having to specify every single key in the JSON as attributes? Say I only need :first_name, :last_name, :country for my views -- unless I also specify the other keys in the…
Mark Boulder
  • 13,577
  • 12
  • 48
  • 78
0
votes
1 answer

ActiveModel::Serializers and Ember Data - Correctly modeling my serializer to be used with Ember Data

In my app, a Post has_many Comments and a Comment belongs_to Post (modeled via the has_one relationship in my serializers). Since I get the Stack Level Too Deep error message whenever I attempt to model both of these relationships in my serializers,…
Kurt Mueller
  • 3,173
  • 2
  • 29
  • 50
0
votes
1 answer

Overriding the embed_key in Active Model Serializer

I have a serializer with some has_many associations where I've modified the embed_key. I'm trying to have the IDs for my model be like path-name rather than 12. The code below is making that happen: class SymbolSerializer < ActiveModel::Serializer …
BJ McDuck
  • 164
  • 1
  • 12
0
votes
1 answer

Embedding IDs with active model serializers leaves out key names when using composite primary keys

I am using composite primary keys in my Ruby On Rails API server. I am also using Active Model Serializers to manage the serialization of my models. I would like to use the embed: :ids feature in my serializer to embed my IDs. This works with…
0
votes
1 answer

How to do many to many in active model serializer?

I'm looking for a solution to use many to many association in active model serializer. Let's say I have a user with many user types through a many to many table, how can I return the user types for a specific user? Do I need to create a serializer…
Dofs
  • 17,737
  • 28
  • 75
  • 123
0
votes
2 answers

EmberJS Data hasMany sideloading with ActiveModelSerializers

I'm using Ember Data canary build: 1.0.0-beta.8+canary.267214b9 together with a rails back-end and ActiveModelSerializer. My configuration on ember side looks like this: App.ApplicationSerializer =…
kunerd
  • 1,076
  • 10
  • 25
0
votes
1 answer

How would you strip something form an active model serialize?

I am looking to use active model serialize on a model called roles, which spits back the roles and that roles permissions. How ever, I want to tell Active Model Serializer that if the role name is Administrator you should never include it in the…
user3379926
  • 3,855
  • 6
  • 24
  • 42
0
votes
1 answer

Expected format for validation errors in Ember Data (using ActiveModel::Serializers)

Unfortunately, ActiveModel::Serializers does not currently support validation errors, though they're scheduled for 1.0. Until then, I've got to hack a solution of my own. The big problem? I have no idea what format Ember Data's ActiveModelAdapter…
nullnullnull
  • 8,039
  • 12
  • 55
  • 107
0
votes
2 answers

I have an attribute (which is a function) and use a specific serializer using Active Model Serializers

I have the following Active Model Serializer and would like to use a specific serializer for a method called notes which is returning an array of notes from the instance. I have tried this and some other variations: class MenuNotesSerializer <…
timpone
  • 19,235
  • 36
  • 121
  • 211
0
votes
1 answer

Rails serializer isn't called on Mongoid embedded class

I have two mongoid models, let's call them Model and ModelChild. This is relation in Model: embeds_many :readings, class_name: 'ModelChild', inverse_of: :model And this is relation in model_child: embedded_in :model, class_name: 'Model',…
xx77aBs
  • 4,678
  • 9
  • 53
  • 77
0
votes
1 answer

How to render JSON Associated data from ActiveRecord Includes

How do I render grids in JSON from includes query? The code below only outputs Folders. Folder.includes(:grids) render json: @folders, :include => :grids, root: false
0
votes
1 answer

Does Active Model Serializers work with JSONP?

If not, how can I make it so that it is JSONP-compliant with my AJAX requests? EDIT: It looks like I am not clear with what I want to achieve. Let's say for example that I have a Post class that contains attributes like id, author, tags and content.…