EmberJS Pushing Records

You can push the records into the store's reserve without asking for the records from an application. The store can restore the record, in the event that it is asked by a course or controller just when record is in the cache.


The model given beneath demonstrates the pushing of records into the coal firebase. Open the application.hbs document made under app/formats/ with the accompanying code −


<h2>Pushing Record into Store</h2> 


{{input type = "name" esteem = nameAddress placeholder = "Enter the content" 

self-adjust = "autofocus"}} 

/when client taps the send catch, the 'saveInvitation' activity will get activated 

<button {{action 'saveInvitation'}} >Send</button> 


{{#if responseMessage}} 

/show the reaction sessage in the wake of sending the content effectively 




Create a model with the name invitation, which will get made under app/models/. Open the document and incorporate the accompanying code −


import DS from 'coal information'; 

send out default DS.Model.extend ({ 

/indicating trait utilizing 'attr()' technique 

name: DS.attr('string') 


Next, make a controller with the name application, which will be made under app/controllers/. Open the record and include the accompanying code −


import Ember from 'coal'; 

send out default Ember.Controller.extend ({ 

headerMessage: 'Just around the corner', 

/shows the reaction message in the wake of sending record to store 

responseMessage: '', 

nameAddress: '', 

activities: { 

/this activity name which fires when client clicks send catch 

saveInvitation() { 

const name = this.get('nameAddress'); 

/make the records on the store by calling createRecord() technique 

const newInvitation = this.store.createRecord('invitation', { name: name }); 

newInvitation.save();/call the spare() strategy to endure the record to the backend 

this.set('responseMessage', 'Bless your heart! We have spared your Name: ${this.get('nameAddress')}'); 

this.set('nameAddress', '');