Skip to content

Instantly share code, notes, and snippets.

@supaspoida
Created October 15, 2012 18:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save supaspoida/3894309 to your computer and use it in GitHub Desktop.
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
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