Skip to content

Instantly share code, notes, and snippets.

@bnhansn
Created October 22, 2016 19:30
Show Gist options
  • Save bnhansn/4112c42b25f90a9fac7e8f3854002fc8 to your computer and use it in GitHub Desktop.
Save bnhansn/4112c42b25f90a9fac7e8f3854002fc8 to your computer and use it in GitHub Desktop.
defmodule Sling.MessageView do
use Sling.Web, :view
def render("index.json", %{messages: messages, pagination: pagination}) do
%{
data: render_many(messages, Sling.MessageView, "message.json"),
pagination: pagination
}
end
def render("message.json", %{message: message}) do
%{
id: message.id,
inserted_at: message.inserted_at,
text: message.text,
user: %{
email: message.user.email,
username: message.user.username
}
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment