Given the following:
A user fills out a Situation form, they add some Emotions and then they add some Places. As a user, I want to view my list of situations and see an individual situation from a native mobile app (i.e. via an API call/JSON response to the Rails app.)
Here are the associations:
A Situation Model. An Emotion Model that belongs to Situation. A Places model that is an HABTM with Situation.
I need to render the JSON for the show action for Situation, however simply using respond_with situation
only renders out the specific fields for Situation and not the associated fields. I need to be able to call the show action and return the complete Situation.
How can I make the show action endpoint actually retrieve the complete situation (with itâs associated records) and not just the Situation by itself? Should I need to create a template with Jbuilder?
Hereâs the relevant parts of the SituationsController. Note, using Decent Exposure, although that doesnât (or shouldnât) have an effect. This is also standard Rails4/ActiveRecord.
class SituationsController < ApplicationController
...
expose(:situations) { current_user.situations }
expose(:situation, attributes: :situation_params)
respond_to :json
def index
respond_with situations
end
def show
respond_with situation
end
...