Created
January 21, 2011 21:59
-
-
Save Gregg/790508 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# So you might have something like this: | |
# <% @presenter.tweets.each do |tweet| %> | |
# <div id="tweet_#{tweet.id}" class="<%= 'favorite' if current_user && tweet.is_a_favorite?(current_user) %>"> | |
# <%= tweet.status %> | |
# </div> | |
# <% end %> | |
# Kinda ugly... this is a simple example of where you might want a block helper so our view becomes: | |
# <% tweet_div(tweet) do %> | |
# <%= tweet.status %> | |
# <% end %> | |
# then we have a helper | |
def tweet_div(tweet, &block) | |
klass = 'favorite' if current_user && tweet.is_a_favorite?(current_user) | |
div_for tweet, :class => klass do | |
yield | |
end | |
end | |
# if we wanted to make it even more testable, we might do | |
def tweet_div(tweet, &block) | |
div_for tweet, :class => tweet_class(tweet) do | |
yield | |
end | |
end | |
def tweet_class(tweet) | |
'favorite' if current_user && tweet.is_a_favorite?(current_user) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment