rabl
rabl copied to clipboard
Mandatory object in partial
If I want to render a partial that does not require an object, like:
# some_template.json.rabl
node(:common) do
# I cannot do like this
# partial('common/duration_units')
# and like this
# partial('common/duration_units', object: {})
# I have to do:
partial('common/duration_units', object: {a: 123})
end
# common/duration_units.json.rabl
node(:available_duration_units) do
DURATION_UNITS.map do |unit|
{
name: unit.name,
multiplier: unit.multiplier
}
end
end
From my point of view it is not the best solution and there should be a way to render a partial without an object.
Another way is to use extends
but I completely fail to understand how to use it whatsoever
extends should work exactly the same way as partial in you situation?
extends('common/duration_units')
doesn't work?
You'll have to rename your file to common/_duration_units.rabl
(note the underscore)