Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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