Skip to content

Instantly share code, notes, and snippets.

@gregblake
Created May 15, 2018 15:16
Show Gist options
  • Select an option

  • Save gregblake/81109b0611c8f7a1b372b95c7135c5ed to your computer and use it in GitHub Desktop.

Select an option

Save gregblake/81109b0611c8f7a1b372b95c7135c5ed to your computer and use it in GitHub Desktop.
Rendering json for Project photos that may or may not be associated with a media_item
def show
project_photo = ProjectPhoto.find(params[:id])
if project_photo.media_item?
media_item = # Some method to lookup the media_item associated with the project_photo
render json: media_item.as_json
else
# You have at least 2 options here. You could:
# 1) refactor the project_photo Boxer representation into a similar as_json method, or
# 2) Modify the existing project_photo Boxer representation, and render the json using Boxer.
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment