Last active
August 29, 2015 14:17
-
-
Save jeregrine/2aedd1d5a798756602e6 to your computer and use it in GitHub Desktop.
View.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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