Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

70 lines (58 sloc) 1.753 kb
var <%= names.constructor.plural %> = function () {
var _this = this;
this.respondsWith = ['html', 'json', 'js', 'txt'];
this.index = function (params) {
<%= names.constructor.singular %>.all(function (err, items) {
if (err) throw err;
params.items = items;
_this.respond({params: params});
});
};
this.add = function (params) {
this.respond({params: params});
};
this.create = function (params) {
var item = <%= names.constructor.singular %>.create(params);
item.save(function (err, res) {
if (err) {
params.errors = err;
_this.transfer('add');
}
else {
_this.redirect({controller: _this.name});
}
});
};
this.show = function (params) {
<%= names.constructor.singular %>.find(params.id, function (err, items) {
if (err) throw err;
params.item = items[0];
_this.respond({params: params});
});
};
this.edit = function (params) {
<%= names.constructor.singular %>.find(params.id, function (err, items) {
if (err) throw err;
geddy.util.meta.mixin(params, items[0]);
_this.respond({params: params});
});
};
this.update = function (params) {
<%= names.constructor.singular %>.update(params.id, params, function (err, res) {
if (err) {
params.errors = err;
_this.transfer('edit');
}
else {
_this.redirect({controller: _this.name});
}
});
};
this.remove = function (params) {
<%= names.constructor.singular %>.remove(params.id, function (err, items) {
if (err) throw err;
_this.redirect({controller: _this.name});
});
};
};
exports.<%= names.constructor.plural %> = <%= names.constructor.plural %>;
Jump to Line
Something went wrong with that request. Please try again.