Skip to content

Commit

Permalink
Update crud controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
1602 committed Oct 11, 2011
1 parent e1647ce commit 024029d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"connect": ">= 0",
"socket.io": ">= 0",
"jugglingdb": ">= 0",
"express": ">= 2.2.2",
"yaml": ">= 0.1.2",
"coffee-script": ">= 1.1.1",
Expand Down
12 changes: 6 additions & 6 deletions templates/crud_controller.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
before ->
Model.findById params.id, (err, model) =>
Model.find params.id, (err, model) =>
if err
redirect path_to.models
else
Expand All @@ -13,18 +13,18 @@ action 'new', ->
render()

action 'create', ->
Model.create body, (id) =>
if !id
Model.create body, (err, model) =>
if err
flash 'error', 'Model can not be created'
@model = this
@model = model
@title = 'New model'
render 'new'
else
flash 'info', 'Model created'
redirect path_to.models

action 'index', ->
Model.allInstances (models) =>
Model.all(err, models) =>
@models = models
@title = 'Models index'
render()
Expand All @@ -38,7 +38,7 @@ action 'edit', ->
render()

action 'update', ->
@model.save body, (err) =>
@model.updateAttributes body, (err) =>
if !err
flash 'info', 'Model updated'
redirect path_to.model(@model)
Expand Down
12 changes: 6 additions & 6 deletions templates/crud_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ action('new', function () {
});

action('create', function () {
Model.create(body, function (id) {
Model.create(body, function (err, user) {
if (!id) {
flash('error', 'Model can not be created');
render('new', {
model: this,
model: user,
title: 'New model'
});
} else {
Expand All @@ -23,9 +23,9 @@ action('create', function () {

action('index', function () {
this.title = 'Models index';
Model.allInstances(function (models) {
Model.all(function (err, models) {
render({
models: models,
models: models
});
});
});
Expand All @@ -41,7 +41,7 @@ action('edit', function () {
});

action('update', function () {
this.model.save(body, function (err) {
this.model.updateAttributes(body, function (err) {
if (!err) {
flash('info', 'Model updated');
redirect(path_to.model(this.model));
Expand All @@ -65,7 +65,7 @@ action('destroy', function () {
});

function loadModel () {
Model.findById(params.id, function (err, model) {
Model.find(params.id, function (err, model) {
if (err) {
redirect(path_to.models);
} else {
Expand Down

0 comments on commit 024029d

Please sign in to comment.