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

How to retrieve related data from deeply nested resources

I have deeply nested resources below: resources :venues, shallow: true do #Halls get "hall/:id/exhibition" => "halls#exhibition", as: :exhibition get "hall/:id/visit" => "halls#visit", as: :hall_visit get…
0
votes
0 answers

ActiveModel::ArraySerializer and Doorkeeper gem interaction

So I'm trying to build rails API app with rails 4 and ruby 2.0.0 ActiveModelSerializer gem (0.8.1) and Doorkeeper gem(actually it's fork (https://github.com/simonbnrd/doorkeeper) for using this game with mongoid 4, but I don't think that's the…
0
votes
2 answers

Trying to get many to many to work with Rails and Emberjs

I'm trying to get many to many associations to work with Ember JS and Rails but it doesn't seem to be rendering the Role Name Below are the files: users/index.hbs {{#each}} {{id}} …
0
votes
0 answers

ActiveModelSerializer requires functions in right order

Working on front-end and json responses on RoR backend, I'm trying to set up serializers to avoid code cluttering with :only => [] and so on. What I find out, is that in serializer with associations we can't use name of class, which is not yet…
ProdoElmit
  • 1,067
  • 9
  • 22
0
votes
2 answers

Use case for Active Model Serializer `embed :ids, include: true` with Ember

My ember router has this type of parent/child resource set up. this.resource("cities", function(){ this.resource("city", { path: ':city_id'}); }); In the backend (which is Rails), there is a has_many relationship between City.rb and…
BrainLikeADullPencil
  • 11,313
  • 24
  • 78
  • 134
0
votes
1 answer

ActiveModel dynamic attributes

Sorry if my question is stupid, but I spent lot of time searching solution and I didn't find. I'd like to create an ApiOutputsHandler model without database. So I've created an ActiveModel. This model will be used for custom responses of my API such…
0
votes
1 answer

Multilevel hasMany sideloading

I use ActiveModel::Serializers to get JSON out to an Ember.js application. I use sideloading to maximize the performance. Can I tell ActiveModel::Serializers to sideload all PhoneNumbers in the SwitchboardSerializer?…
wintermeyer
  • 8,178
  • 8
  • 39
  • 85
0
votes
0 answers

loading embedded associations only works with underscores names

I have a model App.Leg that has many App.LegPlayers: App.Leg = DS.Model.extend({ match: DS.belongsTo('App.Match'), legPlayers: DS.hasMany('App.LegPlayer'), winner: DS.belongsTo('App.Player') }); App.LegPlayer = DS.Model.extend({ leg:…
Dave Goulash
  • 125
  • 10
0
votes
1 answer

Rails: do non-ActiveRecord models need to include ActiveModel::Serializers, or just respond to #as_json?

Using Rails 3.2, I'm working on an API backed model (not ActiveRecord). I want to be able to call to_json on this model in Rails controllers. After reading through a bunch of the ActiveModel docs I'm still not clear on one thing: Given a model like…
Andrew
  • 42,517
  • 51
  • 181
  • 281
0
votes
1 answer

josevalim / active_model_serializers controller argument error

I am playing with Jose Valim's active_model_serializers Gem. I am attempting to call a custom serializer in my controller, and it looks like :json is not using the ActiveModel::ArraySerializer as it should. When I define the default…
-1
votes
1 answer

How to sort by attributes in rails serializer?

Just as the title says, how should I sort the api using the attribute in Active Model Serializer in Rails? I have an example api consist of shopping list. It consist product name, location, and price. In my Serializer class ShoppingListSerializer <…
-1
votes
1 answer

How to add different many-to-many field into a single instance or row of a foreign key in django-rest-framework using model serializer

I am creating an ecommerce website using Django-rest-framework and react. I am trying to add items to cart. I am able to add items to the cart on the frontend but I want to store the cart data to the backend (Django) database so that whenever the…
-1
votes
1 answer

Add fields of a table to the parent table in serializers

I have three tables users,posts and comments. The serializer of post is class PostSerializer < ActiveModel::Serializer attributes :id, :content, :like, :created_at, :updated_at attributes :user has_many :comments def user …
-1
votes
1 answer

I cannot run rails s because of Json gem

I was hopping to get some help because I can't run my project. I added an API to my rails project using serializer and Json, but the thing is when I run rails S I got this error on console. I already tried the following Bundle Bundle install…
-1
votes
2 answers

Change in response from serializers after rails upgrade to 4.2.2 from 4.1.9

I was upgrading my rails application from Rails 4.1.9 to 4.2.2.In rails 4.1.9 rspec was green.After the upgrade when i ran the test, i got a couple of rspec failures. Rails version = 4.2.2 Ruby version = 2.2.4 rspec = 3.0.0 Following are the gems…
1 2 3
49
50