Convert HTML code of single quote (i.e. ') to text

When I save a single quote character in my database, it was converted
into & so when I read it out from database to view on my webpage,
this single quote character (and maybe many other special-treated
character) is showed as & which is not expected. I expect the " ’ "
character to be displayed.

How can I convert & to ’ (single quote character) using ruby code?

Please help.
Nam.

I don’t see why this is an issue for you. & is the right
representation, the browser takes care of rendering that as a quote.
You need to see what you are doing with the incoming data before
displaying it. Also, have a look at html_escape() / h() helper
function and sanitize data before database insertion. You shouldn’t
be storing a & into the database text field.

Hi Mukund,
Let me make it clearer to you.
My situation is: I have a textbox to input the data named Username for
example. The user input a string that contains the single quote, e.g.
“Mukund’s name”, then I it was saved into MySQL database.

The text was converted automatically into “Mukund&s name” in the
record inside the database. So, when I view that record on my webpage to
edit it, the text inside my editbox is exactly “Mukund’s name”. I
understand what you mean about the browser automatic convertion, but it
won’t translate it inside the textbox.

I’m not clear aobut your advice to use html_escape(). This helper will
turns single quote " '" into '. What I need is the reverse
direction: converting ’ back to single quote " '".

I google “reverse + html_escape” and found a thread in this forum about
what I need here http://www.ruby-forum.com/topic/908.
I wouldn’t find that without your mention about the h() function. Thank
you Mukund.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs