# RJS & Unicode (again)

**URL:** <https://www.ruby-forum.com/t/rjs-unicode-again/54807>\
**Category:** Rails\
**Created:** [March 14, 2006, 2:57pm UTC](https://www.ruby-forum.com/t/rjs-unicode-again/54807 "2006-03-14T14:57:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://www.ruby-forum.com/u/dave)\
**Post date:** [March 14, 2006, 2:57pm UTC](https://www.ruby-forum.com/t/rjs-unicode-again/54807/1 "2006-03-14T14:57:37Z")

</div>

I have a problem with unicode & RJS. I searched several boards & blogs,  
but was not able to find a solution. Let me explain my problem with an  
example.

View (test.rhtml):  
…

Ã¤Ã¼Ã¶Ã?Ã?Ã?Ã?Ã?Ã?
 ...

Output:  
Ã¤Ã¼Ã¶Ã?Ã?Ã?Ã?Ã?Ã?

RJS-Template (an\_action.rjs):  
page.replace\_html ‘a\_test\_div’, ‘Ã¤Ã¼Ã¶Ã?Ã?Ã?Ã?Ã?Ã?’

Calling ‘an\_action’ changes the content of ‘a\_test\_div’, the output  
should remain the same, but Instead of ‘Ã¤Ã¼Ã¶Ã?Ã?Ã?Ã?Ã?Ã?’ i get  
‘Ã?Â¤Ã?Â¼Ã?Â¶Ã?Â?Ã?Â?Ã?Â?Ã?Â?Ã?Â?Ã?Â?’ which seems to be an encoding problem.

I’ve found a workaround for strings (introduced by Thomas F.) by  
using  
page.replace\_html ‘messageEditor’, ‘Ã¤Ã¼Ã¶Ã?Ã?Ã?Ã?Ã?Ã?’.gsub(/([^\x00-\x9f])/u)  
{ |s| “&#x%x;” % $1.unpack(‘U’)[0] }  
instead of  
page.replace\_html ‘a\_test\_div’, ‘Ã¤Ã¼Ã¶Ã?Ã?Ã?Ã?Ã?Ã?’  
but this strategy of course fails while rendering partials.

Are there any better suggestions?

Thanks  
Dave

---

<div class="post-metadata">

**Author:** ![dave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://www.ruby-forum.com/u/dave)\
**Post date:** [March 14, 2006, 2:59pm UTC](https://www.ruby-forum.com/t/rjs-unicode-again/54807/2 "2006-03-14T14:59:41Z")

</div>

I’m having the same problem too.

---

<div class="post-metadata">

**Author:** ![dave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://www.ruby-forum.com/u/dave)\
**Post date:** [March 14, 2006, 3:07pm UTC](https://www.ruby-forum.com/t/rjs-unicode-again/54807/3 "2006-03-14T15:07:00Z")

</div>

Sorry, I forgot:

A permanent solution can be reached by changing ‘render’ method in  
‘add\_rjs\_to\_javascript\_helper.rb’ to:

def render(\*options\_for\_render)  
(Hash === options\_for\_render.first ?  
@context.render(\*options\_for\_render) :  
options\_for\_render.first.to\_s).  
gsub(/([^\x00-\x9f])/u) { |s| “&#x%x;” % $1.unpack(‘U’)[0] }  
end

but I’m still not shure, if it is really a good one.

Better suggestions are always welcome.
