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

Specify cache_key yourself for ActiveModel Serializers

I have a multi-tenant solution where I would like to cache the outcome of the serializers. Since the cache should be different for the different users, I would like to specify the cache_key myself (e.g. "/accounts/1/tags"). Is this at all possible…
Dofs
  • 17,737
  • 28
  • 75
  • 123
0
votes
2 answers

Formatting JSON from Rails for Ember

At the moment the JSON in my rails API with ember front end app is formatting incorrectly for my images model as shown below. This results in the ember Chrome tool showing the data for my Project_image as 'object Object' and project_id as 'null'…
0
votes
1 answer

Customize JSON output with HAS_MANY related output

I have 2 models Prize and Staff, One staff HAS_MANY prizes I want to export noy only the prize, but also embedded the prize's owner (staff) in the JSON response. How to do it ? render json: Oj.dump( Prize.where(:staff_id => nil) ) Sample output…
user3675188
  • 7,271
  • 11
  • 40
  • 76
0
votes
1 answer

Rails 4 Passing Json To Ember

My Json output is not coming the way as expected by Ember. I am getting the following output: { "user":{ "id":3, "email":"user5@user.com" "username":"user5" }, "uploads":[{ "id":5, "user_id":3, …
codingbear
  • 296
  • 5
  • 18
0
votes
1 answer

Include properties for ActiveModelSerializer only if called within has many

I have a rails app with the following models. class Project has_many :project_clips has_many :clips, through: :project_clips end class Clip has_many :project_clips has_many :projects, through: :project_clips. end class ProjectSerializer <…
ShivamD
  • 931
  • 10
  • 21
0
votes
2 answers

ArrayProxy expects an Array or Ember.ArrayProxy, but you passed object

I am getting this error: ArrayProxy expects an Array or Ember.ArrayProxy, but you passed object I am getting my data from a rails application using active-model-serializers. The data is showing in mhy ember inspector but my template is not…
garthcodes
  • 91
  • 1
  • 6
0
votes
1 answer

Ember render not showing rails or Ember computed properties

I can't seem to get 'computed' properties from a model. In this case, I cannot get the property commented_by My app structure is pretty simple: I have a Post model that has many comments. In the post.hbs where I display a post, I have a section that…
0
votes
1 answer

rails 4 multiple date ranges in one record

I need to add multiple different start_time and end_time dates to this model: class CreateCourses < ActiveRecord::Migration def change create_table :courses do |t| t.string :name t.datetime :start_time t.datetime :end_time …
0
votes
1 answer

Ember adapter and serializer

I'm building an Ember application with ember-cli and, as a persistence layer, an HTTP API using rails-api + Grape + ActiveModelSerializer. I am at a very basic stage but I want to setup my front-end and back-end in as much standard and clean way as…
0
votes
0 answers

ActiveModelSerializer converts Hash to JsonArray after upgrading ruby 2.1.4 and rails 4.2.0beta4

I have the following line of code in my controller: render json: {token: user.token}, status: 200 It used to respond as below: (root node is disabled by default) {'token': 'ace814a7dd50acda5a76ff7e4c9f7252'} Now I get the result as an array and…
turhanco
  • 941
  • 10
  • 19
0
votes
3 answers

ActiveModelSerializer with Sinatra

Can I use active_model_serializers with Sinatra? If not, is there any better way for json output in Sinatra for building a web service?
0
votes
1 answer

Custom path for active_model_serializer serializers

By default, the gem active_model_serializer (from rubygems, the version 0.8.1) looks for the serializers in app/serializers. However, I have a shared directory at the root of Rails project sharing models, serializers, specs with other projects as a…
0
votes
0 answers

Active model serializer output same data for index and show action

When I'm going to index action it outputs whole data from my model, as I understood when I'm going to show action it supposed to output only object depends on id param, but in my case it output the same data as it were in index action. My active…
p0ison
  • 1
0
votes
1 answer

Rendering has_many in ActiveModelSerializer conditionally

I have the following serializers: class V1::CategorySerializer < ActiveModel::Serializer has_one :category_name, :class_name => 'V1::CategoryName' has_many :brands, :class_name => 'V1::Brand' end class V1::CategoryNameSerializer <…
Vedant Agarwala
  • 18,146
  • 4
  • 66
  • 89
0
votes
1 answer

Serializing Conditionally on Active Model Serializers

invoice_serializer.rb class InvoiceSerializer < ActiveModel::Serializer attributes :id, :document_no, :customer_id, :currency_id, :date, :due_date, :notes, :invoice_status_id, :total, :tax_total, :grand_total # This is not working,…