From the course: Ember.js Essential Training
Unlock this course with a free trial
Join today to access over 22,400 courses taught by industry experts.
Create a new record - Ember.js Tutorial
From the course: Ember.js Essential Training
Create a new record
- [Teacher] To create a new record, we first need a model for our component to have access to. So to begin, we'll add a model hook for our bookmark's new route. We can open up our route file for the bookmark's new route at app, routes, bookmarks, new. In our Route.extend code block, we need to add a model hook, and in this case, because we're creating a new instance of the bookmark, we're going to call the stores method createRecord. So this will look like return this.get('store').createRecord and pass the string of the model name that we are creating. For here, obviously it's going to be bookmark. Now what we need at this point is we need our component to then save the bookmark record. We don't need access to the store in our component, as the bookmark object itself has access to its own save method to persist the data to the server. Let's open up the component now and start building in the ability for us to save our new bookmark record. We'll open up app, components, bookmarks…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.