Skip to content

Instantly share code, notes, and snippets.

@teamon
Created May 15, 2012 20:36
Show Gist options
  • Save teamon/2704934 to your computer and use it in GitHub Desktop.
Save teamon/2704934 to your computer and use it in GitHub Desktop.
Backbone.js jQuery file upload with autosave
# This will automatically create or update model
onRender: =>
[method, url] = if @model.isNew()
["POST", mymodels_path()]
else
["PUT", model_path(@model.id)]
@$(".upload").fileupload(
dataType: 'json'
type: method
url: url
formData: {"_method": method}
done: (e, data) =>
@model.set(id: data.result.id)
@render()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment