Skip to content

Instantly share code, notes, and snippets.

@turboMaCk
Created September 6, 2014 12:12
Show Gist options
  • Save turboMaCk/ce96364b40c6120872e1 to your computer and use it in GitHub Desktop.
Save turboMaCk/ce96364b40c6120872e1 to your computer and use it in GitHub Desktop.
Rabl-Rails has_many relation render array of IDs
# object.json.rabl
# This is not regular rabl template
# This example is using rabl-rails gem: https://github.com/ccocchi/rabl-rails
object :@product
attributes :id, :name, :description
node :categories do |item|
item.categories.map do |category|
category.id
end
end
/* api render */
{
product: {
id: 1,
name: "name of product",
description: "Desc of product",
categories: [1,2,3]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment