0

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?

Jim MacKenzie
  • 222
  • 4
  • 16
  • possible duplicate of [Ember Data model's errors property (DS.Errors) not populating](http://stackoverflow.com/questions/24027053/ember-data-models-errors-property-ds-errors-not-populating) – Kingpin2k Jun 09 '14 at 23:29
  • I'm not completely sure as I am using activemodel, but I'll look into those ideas. – Jim MacKenzie Jun 10 '14 at 02:48
  • `App.ApplicationAdapter = DS.ActiveModelAdapter;` ? We can totally look more into it if you are using that adapter client side and the errors aren't showing up. – Kingpin2k Jun 10 '14 at 02:56
  • Yes, we are using `App.ApplicationAdapter = DS.ActiveModelAdapter;` – Jim MacKenzie Jun 10 '14 at 15:11
  • Delete this question...I introduced the error when I was testing things and didn't realize I hadn't put ember-data.js back the way it originally was. – Jim MacKenzie Jun 10 '14 at 18:43

0 Answers0