Skip to main content

All Questions

Filter by
Sorted by
Tagged with
0 votes
0 answers
69 views

Using scope in assoc. records JSON response - Rails 5 [duplicate]

Let's say I have a class called Post which has_many :authors, and Author has a number of associations I am including in my #index json response like so: post.as_json( include: [ authors: {...
dimitry_n's user avatar
  • 3,019
0 votes
0 answers
277 views

Force rails to read attribute instead association

I have a bit of a weird issue. I'm trying to refactor some code and currently I've a model set up as: class Level < ActiveRecord::Base serialize :states, Array end And in above the serialized ...
anonn023432's user avatar
  • 3,122
1 vote
0 answers
186 views

Association not working in serializer

So I have two tables questions and answers, a question has many answers. I built a serializer to show the answers from questions as such: Questions serializer: class QuestionSerializer < ...
Robin Gonzalez Valero's user avatar
2 votes
1 answer
445 views

Superclass mismatch for serializer

The serializer for Article has two nested serializers: Author and Chapter. The latter two also have their own individual serializers. I'm using the active_model_serializer gem. # The nested ...
Marty's user avatar
  • 2,234
2 votes
1 answer
369 views

Rails ActiveRecord - Uniqueness and Lookup on Array Attribute

Good morning, I have a Rails model in which I’m currently serializing an array of information. Two things are important to me: I want to be able to ensure that this is unique (i.e. can’t have two ...
Brandon's user avatar
  • 3,130
1 vote
1 answer
1k views

How can I make associations loaded in rails 3 in JSON?

In my rails 3.1 application, I have Lists, which have many tasks. All the associations are setup appropriately, I can call aList.tasks, to and I can see the tasks for the List. However, when I load /...
Ethan Mick's user avatar
  • 9,607
1 vote
1 answer
589 views

overriding as_json for as_json(:includes => :association)

I have two classes, Foo and Bar. Foo has_many Bars. Bar is actually the superclass of several classes that are sharing a STI table. I want to make a dump of my Foo records including their associated ...
CharlieMezak's user avatar
  • 5,999