Skip to content

Instantly share code, notes, and snippets.

Created December 20, 2012 13:41
Show Gist options
  • Save anonymous/4345376 to your computer and use it in GitHub Desktop.
Save anonymous/4345376 to your computer and use it in GitHub Desktop.
Coffeescript snippet for use with jQuery-File-Upload that works with the iframe transport plugin as well as ajax which means it works in IE9 as well as Chrome etc.
$form.fileupload
dataType: "json"
done: (e, data, extra) ->
result = if data.result?
data.result
else
data = JSON.stringify(data).replace(/"name":"utf8","value":"[^"]*"/, '"name":"utf8","value":"REMOVED"')
JSON.parse(data).result
console.log result
class MyController < ApplicationController
def my_action
# Do whatever you need to do
respond_to do |format|
format.js { render json: to_json(@agent) }
format.html { render text: "<textarea data-type=\"application/json\">#{to_json(@agent)}</textarea>" }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment