ruby-on-rails – Truncate text and don't show unwanted characters with rails


I'm using the truncate function to show part of a text, along with this function I added the html_safe function so that the text doesn't show unwanted characters. But when the text is longer than the limit I set, length: 150 , the unwanted characters reappear.

I would like a solution for this, truncating the text but not showing the unwanted characters.

<%= truncate(service.description.html_safe, length: 15, )


A gem truncate_html talvez resolva teu problema

Exemplo de entrada: <p>This is <em>my <strong>first</strong> post</em></p>

Usando a gem: <%= truncate_html post.title, :length => 15 %>

Saída: <p>This is <em>my <strong>fir&hellip;</strong></em></p>

Scroll to Top