Skip to content

Instantly share code, notes, and snippets.

@davelyon
Created April 4, 2012 13:41
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 davelyon/2301113 to your computer and use it in GitHub Desktop.
Save davelyon/2301113 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
def self.present as, from, klass
if from.to_s.singularize == from.to_s
expose(as) { klass.new send(from) }
else
expose(as) { send(from).map { |orig| klass.new(orig) } }
end
end
end
# In another controller...
expose(:people)
present(:pretty_people, :people, PrettyPeoplePresenter)
# In your view
- pretty_people.each do |pretty|
render :pretty_pretty, pretty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment