0

I'm using Draper to decorate my objects.

I have a model 'starts' that has_one horse. I have a horse decorator that has a boy_or_girl method that I have refactored form the horse mode.

#{start.horse.boy_or_girl}"

I'm getting a method not found on the boy_or_girl method. How do i decorate the related horse?

Will
  • 4,498
  • 2
  • 38
  • 65

1 Answers1

2

Can't you just call draper in your partial #{start.horse.decorate.boy_or_girl}"?

If you want to call the decorator only in the controller, you should use decorates_association

I guess you will have something like

class StartDecorator < Draper::Base
  decorates :start
  decorates_association :horses
  ...
end

class HorseDecorator < Draper::Base
  decorates :horse

  def boy_or_girl
    # your code
  end
  ...
end

See also this question

Community
  • 1
  • 1
mdemolin
  • 2,514
  • 1
  • 20
  • 23
  • ug. im an idiot. didn't restart rails after adding draper. yes, start.horse.decorate.boy_or_girl works. thanks. – Will Aug 03 '13 at 23:51