I'm working on an Ember app using Ember Data and a Rails REST API. I can't seem to get errors to display.
I have a template that looks like this:
{{#each errors.messages}}
<div class="error">
{{message}}
</div>
{{/each}}
<form {{action 'signUp' on='submit'}}>
<div class='form-group'>
{{#each errors.email}}
<div class="error">
{{message}}
</div>
{{/each}}
{{input value=email class='form-control input-lg' placeholder='Email' id='email'}}
</div>
<div class='form-group'>
{{#each errors.password}}
<div class="error">
{{message}}
</div>
{{/each}}
{{input value=password class='form-control input-lg' type='password' placeholder='Password'}}
</div>
<button type='submit' class='btn btn-danger btn-block btn-lg'>Sign up</button>
</form>
Its controller looks like this:
export default Ember.ObjectController.extend({
actions: {
signUp: function() {
var controller = this;
var model = this.get('model');
model.save().then(function() {
controller.transitionToRoute('landing');
}).catch(function() {
// errors should just display on the page
});
}
}
});
And the route looks like this:
export default Ember.Route.extend({
model: function() {
return this.store.createRecord('user');
}
});
I submit the form without entering data, and the server response is:
{"errors":{"email":["can't be blank"],"password":["can't be blank"]}}
But the errors don't show up on the page.
I've gotten errors to work with Ember Data before, and I've also seen someone else run into this problem and never been able to figure out why. I'd be very grateful if anybody could help me figure out why the errors won't display.
Thanks!