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

Unknown adapter: json_api. Valid adapters are: [":fragmentcache", ":json", ":flattenjson", ":null", ":jsonapi"]

I have rails4 running with active_model_serializers (0.10.0.rc2) gem. Today I start developing the api for my client device. I run rspec test, It gave me this error ArgumentError: Unknown adapter: json_api. Valid adapters are: [":fragmentcache",…
channa ly
  • 9,479
  • 14
  • 53
  • 86
0
votes
1 answer

has_many with a scope super slow with STI

class User < ApplicationRecord has_many :buckets, -> { order(ranked_row: :asc) } delegate :incomes, :fixed_costs, :financial_goals, to: :buckets ... end I have Buckets, that are STI'd. If I add that scope to the has_many, my page takes…
Dudo
  • 4,002
  • 8
  • 32
  • 57
0
votes
1 answer

Defining multiple attributes in rails AMS

I have Organization serializer as follow: class OrganizationSerializer < ActiveModel::Serializer attributes :user_first_name, :user_last_name, :user_email has_many :user def user_first_name …
Akadisoft
  • 306
  • 1
  • 2
  • 13
0
votes
1 answer

Passing fields parameter to AMS JSONAPI serializer

I want to set the fields with a value being passed through the URL. For example right now I can do this: def index authors = Author.all render json: authors, include: params[:include], fields: {authors: [:id], posts: [:title]} end And this…
Caleb Sayre
  • 401
  • 1
  • 4
  • 12
0
votes
1 answer

Active Model Serializer Pagination Link Not Generated

I'm using the master Active Model Serializer and the Pagination Serializer. This is may Pagination Serializer # pagination collection serializer class PaginationSerializer < ActiveModel::Serializer::CollectionSerializer def initialize(object,…
0
votes
1 answer

Hash to Active Model Serializer

I have a hash @branches that is basically: {1 => 5}, {2 => 6} Is it possible for me to send this to a serializer and get output json like so: { branch_id: 1, branch_name: 'Hello', count_5} I've made a custom serializer and calling it like so:…
0
votes
1 answer

Rails active_model_serializer conditional include

When I have a has_many/belongs_to relationship in Rails 5 API with active_model_serializers I can pass the option to include a nested model. def show render json: @post, include: ['comments'] end It's also possible to get multiple layers of…
0
votes
1 answer

Mapping through Paperclip image styles

I have an Album that uses the Paperclip gem to store artwork image uploads. The artwork attribute has a list of styles of different image sizes: thumb, medium, and large. class Album < ActiveRecord::Base has_attached_file :artwork, styles: {…
0
votes
1 answer

Rails serializer default value

I have a simple blog application where users can vote on articles. When a user is logged in the index method in my articles controller returns an additional column indicating whether the current_user has voted for the article. I do this with a raw…
Josh M.
  • 387
  • 4
  • 13
0
votes
1 answer

How do I properly set up a single-table inheritance structure using Ember's Active Model Adapter and Rails' Active Model Serializer?

I'm creating a board game with a human player vs. a bot player, both types stored on a players table with a type column. Each player has their own board. I have a Rails API using the active model serializer gem. My ember app connects to it using…
0
votes
0 answers

Active Model Serializer ArraySerializer explicitly instantiate with to_json without root

I'm using the gem 'active_model_serializers' version 0.9.3. I will minimize my model for simplicity. I have a Center model with attributes id, title and a CenterSerializer, and also CentersCollectionSerializer. Now my question is when I instantiate…
0
votes
3 answers

Rails 4: ActiveModelSerializer how to include only those records which are approved?

In my Rails 4.2 API, I'm using active model serializers for constructing json response. Suppose Post is a model and it has many comments and I only want to include comments which are approved/published. I'm using a scope called approved which gives…
lightsaber
  • 1,481
  • 18
  • 37
0
votes
2 answers

Show serializer attribute only for current user and certain role

I need the auth_token attribute to only be outputted for the current authenticated user. My User controller has class Api::V1::UsersController < ApplicationController before_action :authenticate_with_token!, only: [:show, :create, :update,…
Grug
  • 1,870
  • 5
  • 25
  • 38
0
votes
2 answers

Implement sparse fieldset in Rails API

I'm using rails-api with serializers and I'm especially looking for an easy way to implement "sparse fieldset", that means I want my Rails API to render (json) only the fields I give in the parameter…
0
votes
2 answers

Optional attribute in activemodel serializer in ruby on rails

I have following two Serializer class. In index controller I want skip loading project_products, only show/edit method I want to fetch project_product details. class ProjectSerializer < ActiveModel::Serializer attributes :id, :name, :category,…
Santi
  • 620
  • 8
  • 22