Search code examples
ember.jsember-data

Ember Data not sending to server


I have the following code:

app/models/account.js:

import DS from 'ember-data';

export default DS.Model.extend({
  username: DS.attr('string'),
  birthdate: DS.attr('date'),
  gender: DS.attr('boolean'),
  emailaddresses: DS.attr()
});

and app/components/account-profile.js:

import Ember from 'ember';

export default Ember.Component.extend({
  buttonLabel: 'Send to Server',
  actions: {
    buttonClicked(param) {
      this.sendAction('action', param);
    }
  }
});

and app/templates/components/account-profile.hbs

<div class="box">
  <div class="title">Your Profile</div>
  <div>Username: {{account.accountprofile.username}}</div>
  <div>Email Address: {{account.accountprofile.emailaddresses.0.emailaddress}}</div>
  <div>Birthdate: {{account.accountprofile.birthdate}}</div>
  <div>Gender: {{account.accountprofile.gender}}</div>
</div>
<div>
  <div>
    <label>Username</label>
    <div>
      {{input type="text" value=account.accountprofile.username }}
    </div>
    <label>Username</label>
    <div>
      {{input type="text" value=account.accountprofile.emailaddresses.0.emailaddress }}
    </div>
    <label>Username</label>
    <div>
      {{input type="text" value=account.accountprofile.birthdate }}
    </div>
    <label>Username</label>
    <div>
      {{input type="text" value=account.accountprofile.gender }}
    </div>
    <div>
      <div>
        <button type="submit" {{action 'buttonClicked' account}}>{{buttonLabel}}</button>
      </div>
    </div>
  </div>
</div>

I do not see any traffic being sent from from my web browser to my server.

What is missing and what's wrong with my code? What other things I need to do?


Solution

  • Refer Persisting Records in ember guides

    Records in Ember Data are persisted on a per-instance basis. Call save() on any instance of DS.Model and it will make a network request.

    You need to call save method from the record account.accountprofile like this this.get('account.accountprofile').save()