Skip to content

Instantly share code, notes, and snippets.

@alduro
Last active January 12, 2017 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alduro/027dc9c7104b03be74986faec2961210 to your computer and use it in GitHub Desktop.
Save alduro/027dc9c7104b03be74986faec2961210 to your computer and use it in GitHub Desktop.
def render("product.json", %{product: product}) do
%{id: product.id,
name: product.name,
description: product.description,
price: product.price}
|> add_options(product)
end
defp add_options(json, %{product: product}) do
options =
product
|> ExRushlookApi.Repo.preload(:options)
|> render_many(ExRushlookApi.OptionView, "show.json")
Map.put(json, :options, options)
end
defp add_options(json, _product) do
json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment