Skip to content

Instantly share code, notes, and snippets.

@reu
Created June 16, 2012 20:03
Show Gist options
  • Save reu/2942384 to your computer and use it in GitHub Desktop.
Save reu/2942384 to your computer and use it in GitHub Desktop.
Simplest "presenter" ever
class Presenter < BasicObject
def initialize(object)
@object = object
end
def method_missing(method, *args, &block)
@object.send method, *args, &block
end
module RailsHelpers
private
def t(*args, &block)
I18n.t(*args, &block)
end
def l(*args, &block)
I18n.l(*args, &block)
end
def r
Rails.application.routes.url_helpers
end
def h
ApplicationController.helpers
end
end
end
class UserPresenter < Presenter
include RailsHelpers
def link
h.link_to name, r.user_path(@object)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment