Skip to content

Instantly share code, notes, and snippets.

@Irostovsky
Created February 22, 2018 10:20
Show Gist options
  • Save Irostovsky/9d6431342b16a3b2abf09971b37b2db2 to your computer and use it in GitHub Desktop.
Save Irostovsky/9d6431342b16a3b2abf09971b37b2db2 to your computer and use it in GitHub Desktop.
Decorator for the PORO
class FooPresenter
include Draper::Decoratable
attr_accessor :user
def initialize(user)
@user = user
end
def name
user.name
end
def price
123
end
end
class FooPresenterDecorator < Draper::Decorator
delegate_all
def name
object.name.upcase
end
def price
h.number_to_currency object.price
end
end
FooPresenter.new(User.first).decorate.price
> "£123.00"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment