Created
October 15, 2012 18:47
-
-
Save supaspoida/3894309 to your computer and use it in GitHub Desktop.
Trivial example of a view model using dependency injection to access view context
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
class Controller | |
expose(:person) { PersonView.new(Person.first, self) } | |
end | |
class Decorator | |
attr_reader :controller, :object | |
def initializer(object, controller) | |
@object, @controller = object, controller | |
end | |
def view | |
controller.view_context | |
end | |
end | |
class PersonView < Decorator | |
def profile_link | |
view.link_to object.profile | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment