Skip to content

Instantly share code, notes, and snippets.

@rjcorwin
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save rjcorwin/9494916 to your computer and use it in GitHub Desktop.

Select an option

Save rjcorwin/9494916 to your computer and use it in GitHub Desktop.
Boiler Backbone.js helper code for a Form Route to do CRUD operations on a Model.
// Boiler Backbone.js helper code for a Form Route to do CRUD operations on a Model.
FormRoute = function(modelId, modelClass, formClass, redirect) {
var model = new App.Models[modelClass]()
var form = new App.Views[formClass]({model: model})
App.$el.children('.body').html(form.el)
form.once('Form:done', function() {
Backbone.history.navigate(redirect, {trigger: true})
})
if (modelId) {
model.id = modelId
model.fetch({success: function() {
form.render()
}})
}
else {
form.render()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment