1

I have tree models: Tours, buses and locations Tour have more buses, buses more locations.

I want to return json object with buses last locations for some tour.

Pseudo example:

  BUSES

    BUS1
      last_location
    /BUS1

    BUS2
      last_location
    /BUS2

    BUS3
      last_locaiton
    /BUS3

  /BUSES

tour.buses will give me buses for that tour, and bus.locations.last latest location.

I know that is no since fiction, but I don't know how to pack this in one json object to return it :|

1 Answer 1

1

You could do it like this:

both_pieces = {
    :tour          => tour,
    :last_location => bus.locations.last
}

And then send both_pieces back as JSON. Then the client would get one JSON object with the tour and last_location objects inside it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.