valibuk.net

A place for opinions and notes of a valibuk.

Observing more fields with AJAX helper and Unicode

Tagged with: — ondrej at 11:01 pm on Monday, October 2, 2006

Ruby on RailsIn my post about using the observe_field helper for observing more fields I used the escape method (on the client side).

I have found out the code does not work correctly with Unicode characters :(

The JavaScript escape method encodes characters differently and a RoR application cannot handle such parameter value correctly.

  • an ASCII character < 128: as it is
  • an ASCII character 128-255: %NN
  • a Unicode character not included in the ASCII: %uNNNN

The reffered post also contains a method that encodes all characters from the extended ASCII (128-255) and all Unicode characters not included in the ASCII in the same way, that is %uNNNN.

If you would use the method (unicodeEscape), there is a possibility to still use my observe_fields method, but each value has to be pre-processed with the following code from a Korean Ruby forum:

  1. value = params[:param].gsub(/%u([0-9a-fA-F]{4})/) { [$1.to_i(16)].pack(‘U*’) } rescue nil

Well, it is simpler to use the observe_form method, isn’t it? :)

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • DZone
  • Digg
  • Reddit
  • Technorati
  • Furl
  • NewsVine
  • Slashdot
  • Ma.gnolia
  • StumbleUpon

3 Comments »

Comment by jan

February 13, 2007 @ 6:32 pm

Well it helped me.
Using observe_form might be easier, but it’s not really the right solution when you need to “observe” only a few fields on a bigger form (and inefficiency is only the first problem).

Thanks! (golde czechoslovak hande;)

Pingback by valibuk.net » How to observe more fields with AJAX helper

February 13, 2007 @ 10:53 pm

[...] Added:If you need to handle Unicode characters, you should read how to get a parameter value in a controller from my newer post Observing more fields with AJAX helper and Unicode. [...]

Comment by ondrej

February 13, 2007 @ 11:07 pm

You are welcome :)

It is good to hear that it is helpful for somebody, thanks :)

(golde czechoslovak hande> presne tak :)

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Comment Preview


commercial break :)

Make an account on slicehost.com -- a really good hosting where you have your own virtual machine. I installed Gentoo there = I like it very much ;)