11

My environment:

I'm using nested resources and having trouble figuring out where to declare the decorator.

#app/controllers/users_controller.rb
def show
  @user = UserDecorator.find(params[:id])
  @items = @user.items
end

#app/controllers/items_controller.rb
def show
  @item = @user.items.find(params[:id])
end

I tried replacing items with ItemDecorator and it didn't work. Where should I be putting it?

I know that Draper has issues with nested resources in forms, but this isn't a form!

Robin
  • 8,162
  • 7
  • 56
  • 101
sethherr
  • 127
  • 2
  • 10
  • similar to http://stackoverflow.com/questions/10870306/how-should-i-use-draper-in-my-applicationcontroller – Robin Jun 07 '12 at 20:23

1 Answers1

11

As far as I've understood your problem correctly, you've a model user which has many items, but your items were not decorated?

So add to your UserDecorator:

class UserDecorator < Draper::Base
  decorates :user
  decorates_association :items #, :with => :item 

  [..]
end

class ItemDecorator < Draper::Base
  decorates :item

  [..]
end

Have a look on the source.

Robin
  • 8,162
  • 7
  • 56
  • 101