ruby - Rails nested association. in render :json -


The 90% of the current questions asked me what I want, but I have found a bottleneck.

I have the checkins model, and there is a person model. Checkins related to People .

In my controller, I have this code:

  data = check in. Json: {data: data}  

For each checkin , I want to nest it in affiliate person past stack overflow questions Recommend that I do this:

  data = checkin Presenting all Jason: data.to_json includes :: person  

But, it makes it difficult as I originally did, like the nest inside my cover Jason object To make, because to_json creates a string, no hash not.

I want the wrap JSNA object so that I can follow a standard JSON output, where data is always in the data: field, and the other Metadata can be linked to feedback.

How can I get the effect of : to_json while keeping the cover object? Specifically, this is not a valid answer for me, because it's really ugly:

  submit data = checkin.AL json: {data: JSON.parse data.to_json (in it Includes: person)}  

Thanks! There is hope that there is a idiotic way to do this in the railways.

Active Records Curious loading

< Pre> @users = User.all.includes (checkins)

will inquire:

but it does not allow you to present your nested object, what you are looking for is something to decorate your data

Take a look or github .com / rails / jbuilder

You will be able to provide a decorator with templates and data objects to render


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -