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.65k stars 335 forks source link

Can't use child alias with conditional #395

Open jfeust opened 11 years ago

jfeust commented 11 years ago

The following works as it should with the conditional:

collection @publish_times
child(:task, :if => lambda { |publish_time| publish_time.task_id.present? }) do
    extends "api/tasks/task"
end

But as soon as I try to alias the child object it throws an error:

# remove the alias (:todo) or the conditional (:if) and this works
collection @publish_times
child(:task => :todo, :if => lambda { |publish_time| publish_time.task_id.present? }) do
    extends "api/tasks/task"
end

Error:

ActionView::Template::Error (undefined method `card_image' for :task:Symbol):

Where "card_image" is a method call on the task in _task.json.rabl

roelbondoc commented 11 years ago

This should work (wrap the child and alias in braces):

child({:task => :todo}, :if => lambda { |publish_time| publish_time.task_id.present? }) do
    extends "api/tasks/task"
end