I want to convert a string with an email address into ASCII characters for placing in a HTML document. What’s the easiest way to do this?
I keep getting an array back in my HTML document with the characters using this code in my model:
def ascii_email
self.email.each_byte do |e|
"&#", e, ";"
end
end
You’re iterating over the characters in the email address without actually using them, so that’s not going to be what you want.
There’s an important yet subtle difference between an iterator that simply goes through the elements and one that returns the transformed results. Also missing in your snippet was something that turned the transformed array back into a string.