Observing more fields with AJAX helper and Unicode
In 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:
-
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? :)










