Contacts Route
App.ContactsNewRoute = Ember.Route.extend({
model: function () {
return App.Contact.createRecord({name: '', email: ''});
},
actions: {
save: function () {
this.get('store').commit();
this.transitionTo('contacts');
}
}
});
contacts/new.hbs
<form {{action 'save' on="submit"}}>
{{view Ember.TextField valueBinding="name" placeholder="name" required="true" }}
<br />
{{view Ember.TextField valueBinding="email" placeholder="email" required="true" }}
<br />
<button class="btn btn-success" type="submit">Save</button>
<button {{action 'cancel' }} class="btn" >Cancel</button>
</form>
This works fine, but I have to initialize an empty model object in the new page everytime like this
App.Contact.createRecord({name: '', email: ''});
What if there are too many attributes? Wish there existed something similar to Contact.new as in Rails.
Something like this would be really cool or is there any already ?
App.Contact.newRecord();