I'm having problems with validation errors from Rails in ember. I've found a workaround, but it shouldn't be necessary and I'm trying to figure out if I'm doing something wrong.
Here are my original code snippets:
new.handlebars:
{{#if isError}}
<p>There was an error saving the record</p>
{{/if}}
{{#each error in errors.name}}
<p>{{error.message}}</p>
{{/each}}
{{#each error in errors.description}}
<p>{{error.message}}</p>
{{/each}}
new_route.js:
permission.save().then(function(){
self.transitionTo('permissions');
}, function() {
// Couldn't save, do nothing about it.
});
When the above is used, and a validation error is returned, the only thing that appears on the page is "There was an error saving the record". None of the errors code produces anything.
I changed the above code to this:
new.handlebars:
{{#if isError}}
<p>There was an error saving the record</p>
{{/if}}
{{#each error in myerrors.name}}
<p>Name {{error}}</p>
{{/each}}
{{#each error in myerrors.description}}
<p>Description {{error}}</p>
{{/each}}
new_route.js:
permission.save().then(function(){
self.transitionTo('permissions');
}, function(response) {
// Couldn't save, do nothing about it.
self.get('controller').set('myerrors', response);
});
and now, I get the error messages displaying properly.
I'm pretty sure the errors code should work as it was shown above, so I'm confused as to why it wouldn't be working.
Any ideas?