Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update templates/scaffold/controller.ejs

If you are already using function, Model and self can be solved with the use of scopes.
  • Loading branch information...
commit db2e1e8db836fec246d925721159418a9921224c 1 parent 9312e42
@Eraden Eraden authored
Showing with 9 additions and 17 deletions.
  1. +9 −17 templates/scaffold/controller.ejs
View
26 templates/scaffold/controller.ejs
@@ -1,10 +1,11 @@
var <%= names.constructor.plural %> = function () {
+ var self = this,
+ <%= names.property.singular %> = geddy.model.<%= names.constructor.singular %>;
+
this.respondsWith = ['html', 'json', 'xml', 'js', 'txt'];
this.index = function (req, resp, params) {
- var self = this;
-
- geddy.model.<%= names.constructor.singular %>.all(function(err, <%= names.property.plural %>) {
+ <%= names.constructor.singular %>.all(function(err, <%= names.property.plural %>) {
self.respond({params: params, <%= names.property.plural %>: <%= names.property.plural %>});
});
};
@@ -20,8 +21,7 @@ var <%= names.constructor.plural %> = function () {
<% } -%>
<% } -%>
- var self = this
- , <%= names.property.singular %> = geddy.model.<%= names.constructor.singular %>.create(params);
+ var <%= names.property.singular %> = <%= names.constructor.singular %>.create(params);
<%= names.property.singular %>.save(function(err, data) {
if (err) {
@@ -34,25 +34,19 @@ var <%= names.constructor.plural %> = function () {
};
this.show = function (req, resp, params) {
- var self = this;
-
- geddy.model.<%= names.constructor.singular %>.load(params.id, function(err, <%= names.property.singular %>) {
+ <%= names.constructor.singular %>.load(params.id, function(err, <%= names.property.singular %>) {
self.respond({params: params, <%= names.property.singular %>: <%= names.property.singular %>.toObj()});
});
};
this.edit = function (req, resp, params) {
- var self = this;
-
- geddy.model.<%= names.constructor.singular %>.load(params.id, function(err, <%= names.property.singular %>) {
+ <%= names.constructor.singular %>.load(params.id, function(err, <%= names.property.singular %>) {
self.respond({params: params, <%= names.property.singular %>: <%= names.property.singular %>});
});
};
this.update = function (req, resp, params) {
- var self = this;
-
- geddy.model.<%= names.constructor.singular %>.load(params.id, function(err, <%= names.property.singular %>) {
+ <%= names.constructor.singular %>.load(params.id, function(err, <%= names.property.singular %>) {
<%= names.property.singular %>.updateAttributes(params);
<%= names.property.singular %>.save(function(err, data) {
@@ -67,9 +61,7 @@ var <%= names.constructor.plural %> = function () {
};
this.destroy = function (req, resp, params) {
- var self = this;
-
- geddy.model.<%= names.constructor.singular %>.remove(params.id, function(err) {
+ <%= names.constructor.singular %>.remove(params.id, function(err) {
if (err) {
params.errors = err;
self.transfer('edit');
Please sign in to comment.
Something went wrong with that request. Please try again.