Skip to content

Instantly share code, notes, and snippets.

@burgalon
Created June 15, 2020 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burgalon/597de98c66600560e3b9267f62d9ea30 to your computer and use it in GitHub Desktop.
Save burgalon/597de98c66600560e3b9267f62d9ea30 to your computer and use it in GitHub Desktop.
Rails Ellipsis helper with toggle
def ellipsis_text(s, limit=90)
if s&.length>limit
(s.slice(0..limit) +
'... ' +
content_tag(:a, 'More',
class: 'more semibold small',
href: '#',
onClick: "$(this.nextElementSibling).removeClass('hide'); $(this).addClass('hide'); return false;") +
content_tag(:span, s.slice(90..-1), class: 'hide')).html_safe
else
s
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment