Permalink
Browse files

Added validity checks to controller scaffolding for update and create…

… actions.
  • Loading branch information...
1 parent 4814772 commit 9184a755e09726b52d5c05c1195b95ce5a2fe527 @larzconwell larzconwell committed Nov 10, 2012
Showing with 9 additions and 0 deletions.
  1. +9 −0 templates/scaffold/controller.ejs
@@ -23,6 +23,11 @@ var <%= names.constructor.plural %> = function () {
var self = this
, <%= names.property.singular %> = geddy.model.<%= names.constructor.singular %>.create(params);
+ if (!<%= names.property.singular %>.isValid()) {
+ params.errors = <%= names.property.singular %>.errors;
+ self.transfer('add');
+ }
+
<%= names.property.singular %>.save(function(err, data) {
if (err) {
params.errors = err;
@@ -54,6 +59,10 @@ var <%= names.constructor.plural %> = function () {
geddy.model.<%= names.constructor.singular %>.first(params.id, function(err, <%= names.property.singular %>) {
<%= names.property.singular %>.updateAttributes(params);
+ if (!<%= names.property.singular %>.isValid()) {
+ params.errors = <%= names.property.singular %>.errors;
+ self.transfer('edit');
+ }
<%= names.property.singular %>.save(function(err, data) {
if (err) {

0 comments on commit 9184a75

Please sign in to comment.