Skip to content

Instantly share code, notes, and snippets.

@rwilcox
Created September 21, 2011 19:33
Show Gist options
  • Select an option

  • Save rwilcox/1233059 to your computer and use it in GitHub Desktop.

Select an option

Save rwilcox/1233059 to your computer and use it in GitHub Desktop.
presenter_pattern_gone_wrong?
# If the item has one comment, show it, else show the last comment and allow the user to expand
# (yes, a slightly contrived example)
def primary_comment
if self.comemnts.count > 1
"<details class='primary_comment details'><summary><h3>" + self.comments.last.text + " (and #{self.comments.count - 1} others)"
"<ul>"
self.comments.each[0...-1] do |comment|
"<li>" + comment.text + "</li>"
end
else
"<span class='primary_url'>" + self.comments.last.text + "</span>"
end
end
@rwilcox

rwilcox commented Sep 22, 2011

Copy link
Copy Markdown
Author

... which I think I figured out how to make elegant. I'll write a blog post on same in the morning.

@rwilcox

rwilcox commented Sep 23, 2011

Copy link
Copy Markdown
Author

The cunning conclusion to this story can be found on my blog: http://rwilcox.tumblr.com/post/10546160404/presenter-pattern-rails-3-and-html-safe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment