Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

85 lines (69 sloc) 2.57 kB
var <%= names.constructor.plural %> = function () {
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 %>) {
self.respond({params: params, <%= names.property.plural %>: <%= names.property.plural %>});
});
};
<% if(!bare) { %>
this.add = function (req, resp, params) {
this.respond({params: params});
};
this.create = function (req, resp, params) {
<% for(var i in properties) { -%>
<% if(properties[i].name === 'id' && properties[i].type === 'string') { -%>
params.id = params.id || geddy.string.uuid(10);
<% } -%>
<% } -%>
var self = this
, <%= names.property.singular %> = geddy.model.<%= names.constructor.singular %>.create(params);
<%= names.property.singular %>.save(function(err, data) {
if (err) {
params.errors = err;
self.transfer('add');
} else {
self.redirect({controller: self.name});
}
});
};
this.show = function (req, resp, params) {
var self = this;
geddy.model.<%= 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 %>) {
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.property.singular %>.updateAttributes(params);
<%= names.property.singular %>.save(function(err, data) {
if (err) {
params.errors = err;
self.transfer('edit');
} else {
self.redirect({controller: self.name});
}
});
});
};
this.destroy = function (req, resp, params) {
var self = this;
geddy.model.<%= names.constructor.singular %>.remove(params.id, function(err) {
if (err) {
params.errors = err;
self.transfer('edit');
} else {
self.redirect({controller: self.name});
}
});
};
<% } %>
};
exports.<%= names.constructor.plural %> = <%= names.constructor.plural %>;
Jump to Line
Something went wrong with that request. Please try again.