title: Rails - WARNING: Can't verify CSRF token authenticity
body: <p>I'm using some javascript called jpegcam (with paperclip, following <a href="http://lassebunk.dk/2011/02/19/paperclip-jpegcam-webcam-rails3/" rel="nofollow">these directions</a>) and on different occasions it's creating faulty CSRF tokens. This is the only place in application with this issue. The bad tokens have '+' characters in the middle.</p>
  
  <p><strong>This section in the JS is the problem</strong> <code>webcam.set_api_url('&lt;%= upload_users_path %&gt;' + '?' + csrf_param + "=" + encodeURI(encodeURI(csrf_token)));</code></p>
  
  <p>Warning messages:</p>
  
  <pre><code>Started POST "/users/upload?authenticity_token=N0x/rDOgyC6AutbXzx8sZXLwDnB9zQ+NwWefXTpiSfE=" for 127.0.0.1 at 2013- 06-04 01:06:34 -0400
  ...
  Parameters: {"authenticity_token"=&gt;"N0x/rDOgyC6AutbXzx8sZXLwDnB9zQ NwWefXTpiSfE="}
   WARNING: Can't verify CSRF token authenticity
  ...
  Completed 401 Unauthorized in 15ms
  </code></pre>
  
  <p>JS (in page view) looks like this:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function onload_complete(msg) {
      // fetch the CSRF meta tag data
      var csrf_param = $('meta[name=csrf-param]').attr('content');
      var csrf_token = $('meta[name=csrf-token]').attr('content');
  
      // reset the api URL appending the auth token parameter
      webcam.set_api_url('&lt;%= upload_users_path %&gt;' + '?' + csrf_param + "=" + encodeURI(encodeURI(csrf_token)));
  }
  ...
  &lt;/script&gt;
  </code></pre>