Archive for April 2nd, 2009

2nd April
written by simplelight

I was using the Rails helper observe_field to monitor a text entry form on my web app. I couldn’t figure out why the relevant method was not being called until I realized that it was happening every time there was a single quote in the text entry. The solution is simple. Use the escape_javascript function as shown below:

<%= observe_field :guess,
:frequency => 0.5,
:update => 'ajaxWrapper',
:url => {:action => 'feedback', :only_path => false},
:with => "'correct=#{escape_javascript(@text)}&guess='+encodeURIComponent(value)" %>