Skip to content

Instantly share code, notes, and snippets.

@ecoologic
Created June 18, 2011 17:30
Show Gist options
  • Save ecoologic/1033300 to your computer and use it in GitHub Desktop.
Save ecoologic/1033300 to your computer and use it in GitHub Desktop.
presenter for codeschool rails best practices
# /app/presenters/tweets/show.rb
module Tweets
class ShowPresenter
def initialize(tweet)
@tweet = tweet
end
def tweet
@tweet
end
def username
@tweet.user.username
end
def favorites_count
@tweet.favorites.size
end
end
end
class TweetsController < ApplicationController
def show
@presenter = Tweets::ShowPresenter.new(Tweet.find(params[:id]))
@tweet = @presenter.tweet
@username = @presenter.username
@favorites_count = @presenter.favorites_count
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment