Skip to content

Instantly share code, notes, and snippets.

@jeregrine
Last active August 29, 2015 14:17
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 jeregrine/2aedd1d5a798756602e6 to your computer and use it in GitHub Desktop.
Save jeregrine/2aedd1d5a798756602e6 to your computer and use it in GitHub Desktop.
View.ex
defmodule MyApp.MyModelController do
use MyApp.Web, :controller
plug :action
def show(conn, params) do
render conn, "show.json", data: Repo.get!(MyModel, params[:id])
end
end
defmodule MyApp.MyModelView do
use MyApp.Web, :view
@attributes ~W(id body title user comments inserted_at)
def render("show.json", %{data: data}) do
data
|> Map.take(@attributes)
|> Map.update!(:title, &String.capitalize)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment