3

Does anyone know how to use decorator in rabl file?

collection @invitations
  child(:user)
   attributes ....

I want to be able to do this:

collection @invitations
  child(:user => user.decorate)
   attributes ....

This is working well

object false
child UserDecorator.decorate(current_user)

I can't figure out the right syntax for my problem.

Thounder
  • 315
  • 2
  • 14

1 Answers1

0

I think you almost have the right answer. I believe you need to switch the order.

child(user.decorate => :user)

In rabl's documentation, you can add child nodes from an arbitrary data source. Like this:

child @posts => :foobar do
  attributes :id, :title
end

Another approach would be to decorate the user association when you decorate your invitations. If you're using the draper gem, you could do something like this:

class InvitationDecorator < Draper::Decorator
  decorates_association :user
end
Derek Hopper
  • 2,110
  • 12
  • 19