I had the same error and found changing serializer: to each_serializer: in the controller solved the issue. Controller class RecordsController < ApplicationController … def artist @records = Record.where(‘artist_id = ‘ + params[:artist_id]) render :json => @records, each_serializer: RecordSummarySerializer end … end record_summary_serializer.rb – can remove the include line class RecordSummarySerializer < ActiveModel::Serializer attributes :id, :artist_id, … Read more

Use active_model_serializer with a non-ActiveRecord object

The model object needs to include it thusly: # active_model_serializers 0.10+ class ModelName include ActiveModel::Serialization end # active_model_serializers < 0.10 class ModelName include ActiveModel::SerializerSupport end This implements the methods needed within the object, and also auto-discovers the serializer matching the object name, so it can be used transparently just like an ActiveRecord object. This works … Read more

jbuilder vs rails-api/active_model_serializers for JSON handling in Rails 4

It depends on your preference and needs. If you are working with Ember.js front-end, I’d lean towards active_model_serializers since Ember.js was basically crafted to work well with it (Yehuda Katz is one of the maintainers of active_model_serializers and is on the core team for Ember.js; he gave a talk on the topic a while back). … Read more

Test ActiveModel::Serializer classes with Rspec

Assumptions This answer assumes you have the rspec-rails, active_model_serializers and factory_girl_rails gems installed and configured. This answer also assumes you have defined a factory for the Sample resource. Serializer spec For the current version(0.10.0.rc3) of active_model_serializers at the time of writing, ActiveModel::Serializer classes do not receive to_json and are , instead, wrapped in an adapter … Read more

Rails: Serializing deeply nested associations with active_model_serializers

Per commit 1426: https://github.com/rails-api/active_model_serializers/pull/1426 – and related discussion, you can see that the default nesting for json and attributes serialization is one level. If you want deep nesting by default, you can set a configuration property in an active_model_serializer initializer: ActiveModelSerializers.config.default_includes=”**” For detailed reference from v0.10.6: https://github.com/rails-api/active_model_serializers/blob/v0.10.6/docs/general/adapters.md#include-option

Conditional attributes in Active Model Serializers

In the latest version (0.10.x), you can also do it this way: class EntitySerializer < ActiveModel::Serializer attributes :id, :created_at, :updated_at attribute :conditional_attr, if: :condition? def condition? #condition code goes here end end For example: class UserSerializer < ActiveModel::Serializer attributes :id, :username, :name, :email, :created_at, :updated_at attribute :auth_token, if: :auth_token? def created_at object.created_at.to_i end def updated_at … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)