Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8977399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:21:42+00:00 2026-06-15T19:21:42+00:00

I have this html text: <p> I’m a html &nbsp; text</p> To show it

  • 0

I have this html text:

<p> I'm a html &nbsp; text</p>

To show it on my web page, I first sanitize it and remove the tags:

sanitize(best_practice.milestone.description, :tags=>[])

I then shows ok, the &nbsp; is removed.

But if I decide to truncate the text like this:

sanitize(best_practice.milestone.description, :tags=>[]).truncate(30)

The &nbsp; is visible again on my web page. All the special chars will actually be visible.

What can I do to avoid truncate to make this special chars visible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:21:43+00:00Added an answer on June 15, 2026 at 7:21 pm

    Dealing with sanitize helpers and truncation can be tricky. There are a lot of different sanitize helpers: h, CGI::escapeHTML, sanitize, strip_tags, html_safe, etc. Sanitization and truncation do not work well together if a string is truncated between an opening and a closing tag or right in the middle of a special HTML character.

    The following statement seems to work

    sanitize(text, :tags=>[]).truncate(30, :separator => " ").html_safe
    

    The trick is to a pass a :separator option to truncate text at a natural break.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this HTML table: <table width=1100 border=1 style=text-align:center; class=invoice> <tr><td>&nbsp;</td><td>&nbsp;</td><td>Amount Due</td><td>Amount Enc.</td></tr> <tr><td>&nbsp;</td><td>&nbsp;</td><td>CAD
I have this html page which is very simple, it contains a text box
I have this html div tag defined: <div style=height:100px; width:100px class=total-title> first text </div>
I have this html file where I want to overlay some text over another.
I have run this Perl code: #!/usr/bin/perl print content-type: text/html \n\n; print Hello World.\n;
i have a html text like this: <div id=content> <p>para1</p> <p>para2</p> <p>para3</p> <p class=break>para4</p>
I have this issue trying to get all the text nodes in an HTML
I have some HTML like this: <input type=radio class=MyRadio name=TheName> <label for=TheLabel>the text</label> How
I have this HTML/CSS code ( JSBin ): .trackTime{width:50px; text-align:left; float:left;} .trackInputTime{width:45px; height:22px; background-color:#F4F4F4;}
I have this HTML: <div class=info> Some Text Boom A <a onclick=menu('id1');>Link</a> | More

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.