nesquena / rabl

General ruby templating with json, bson, xml, plist and msgpack support
http://blog.codepath.com/2011/06/27/building-a-platform-api-on-rails/
MIT License
3.64k stars 334 forks source link

Mandatory object in partial #636

Open denisovlev opened 9 years ago

denisovlev commented 9 years ago

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

ethicalhack3r commented 9 years ago

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)