1

I added an object nested in another object using the model. Just like this:

Ingresso model ->

def as_json(options=nil) super(:include => [:usuario, :tipo_de_ingresso]) end 

In tipo_de_ingresso model, I want to add another object nested. here:

def as_json(options=nil) super(:include => :entradas) end 

But when I get the the ingressos.json, I lost entradas. If I get tipo_de_ingressos.json, entradas are nested, ok, but when I get ingressos.json, they are not there.

How can I get entradas nested in tipo_de_ingresso when I call ingresso?

1
  • 1
    PS: You might find the RABL Gem helpful if you need to do more complex json operations. That way you can define actual views for your json responses instead of bundling it up in the model.
    – Soup
    CommentedMar 11, 2013 at 23:38

1 Answer 1

5

Try this,

# /app/models/Ingresso.rb def as_json(options=nil) super(:include => [:usuario => {}, :tipo_de_ingresso => { :include => :entradas }]) end 

EDIT:

changed [:usuario, ... to [:usuario => {}, ...

1
  • It works! I knew that was something like this, but I'm not very familiar with Rails. Thanks again :-)CommentedMar 12, 2013 at 17:48

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.