Skip to content

Instantly share code, notes, and snippets.

Created December 24, 2009 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/263285 to your computer and use it in GitHub Desktop.
Save anonymous/263285 to your computer and use it in GitHub Desktop.
View:
- if favorite_comment.text.length < 45
%p= favorite_comment.text
- else
= sample_with_more(favorite_comment.text, favorite_comment.id)
Helper:
def sample_with_more(body, comment_id, html_options = {})
more_link = link_to_function(" &raquo;", "$('more-#{comment_id}').hide(); $('hidden-#{comment_id}').show();", :id => "more-#{comment_id}")
content_tag(:p, html_options) do
body[0..45] + more_link + content_tag(:span, body[46..-1], :style => "display:none", :id => "hidden-#{comment_id}")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment