Skip to content

Instantly share code, notes, and snippets.

@eightbitraptor
Created January 31, 2012 16:11
Show Gist options
  • Select an option

  • Save eightbitraptor/1711353 to your computer and use it in GitHub Desktop.

Select an option

Save eightbitraptor/1711353 to your computer and use it in GitHub Desktop.
decoration
# House Model
class House
has_many: occupants
# ... Other House related methods live here ...
end
# Presenter for a House object
# Deals with visual shenanigans for the view
class HouseDecorator
def initialise(house)
@model = house
end
def formatted_occupants
occupents.inject(String.new) do |acc, o|
acc < "<h2>#{o.name} - #{o.type}"
end
end
# delegates method calls it doesn't know about to the model.
def method_missing(*args)
@model.send(*args)
super
end
end
# in my HTML
<div class="occupants" >
<%= @house.formatted_occupants %>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment