Skip to content

Instantly share code, notes, and snippets.

@jmcelroy5
Last active August 29, 2015 14:11
Show Gist options
  • Save jmcelroy5/b44d63d8d06e5bd42e5a to your computer and use it in GitHub Desktop.
Save jmcelroy5/b44d63d8d06e5bd42e5a to your computer and use it in GitHub Desktop.
// Creating a Backbone Model
var Person = Backbone.Model.extend({
// default attributes
urlRoot:'http://gdibb.herokuapp.com/people', // Is this where the URL goes?
defaults: {
role: 'hater',
imgUrl: 'http://uproxx.files.wordpress.com/2012/09/grumpy-cat-03.jpg',
firstName: 'Grumpy',
lastName: 'Cat'
},
// custom method on a Person model
generateUserName: function(){
var username = this.get('firstName') + this.get('lastName');
this.set('userName', username);
return username;
},
// initialize
initialize: function() {
this.generateUserName();
}
});
// Creating a new person model
me = new Person({id: 123,
imgUrl: 'http://tinyurl.com/lagfw62',
firstName: 'Jessica',
lastName: 'McElroy'});
// Getting 404 error in console when this runs
me.save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment