Created
September 6, 2014 12:12
-
-
Save turboMaCk/ce96364b40c6120872e1 to your computer and use it in GitHub Desktop.
Rabl-Rails has_many relation render array of IDs
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
# 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 |
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
/* 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