Created
January 31, 2012 16:11
-
-
Save eightbitraptor/1711353 to your computer and use it in GitHub Desktop.
decoration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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