Skip to content

Instantly share code, notes, and snippets.

@koos
Created August 30, 2011 11:29
Show Gist options
  • Select an option

  • Save koos/1180701 to your computer and use it in GitHub Desktop.

Select an option

Save koos/1180701 to your computer and use it in GitHub Desktop.
index.rabl
# app/views/posts/index.rabl
collection @posts
attributes :id, :title, :subject
child(:user) { attributes :full_name }
node(:read) { |post| post.read_by?(@user) }
The result of this is a JSON (or XML) looking like this:
[{ post :
{
id : 5, title: "...", subject: "...",
user : { full_name : "..." },
read : true
}
}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment