forked from 1602/compound
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add controller templates for riak Allow people to specify primary key to use for riak
- Loading branch information
Showing
5 changed files
with
159 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ "development": | ||
{ "driver": "riak" | ||
, "host": "localhost" | ||
, "port": "8098" | ||
, "database": "APPNAME-dev" | ||
} | ||
, "test": | ||
{ "driver": "riak" | ||
, "host": "localhost" | ||
, "port": "8098" | ||
, "database": "APPNAME-test" | ||
} | ||
, "staging": | ||
{ "driver": "riak" | ||
, "host": "localhost" | ||
, "port": "8098" | ||
, "database": "APPNAME-staging" | ||
} | ||
, "production": | ||
{ "driver": "riak" | ||
, "host": "localhost" | ||
, "port": "8098" | ||
, "database": "APPNAME-production" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
before -> | ||
Model.findById req.params['id'], (error, model) => | ||
if error | ||
redirect path_to.models | ||
else | ||
@model = model | ||
next() | ||
, only: ['show', 'edit', 'update', 'destroy'] | ||
|
||
action 'new', -> | ||
@model = new Model | ||
@title = 'New model' | ||
render() | ||
|
||
action 'create', -> | ||
Model.create req.body, (error, model) => | ||
if error | ||
flash 'error', 'Model can not be created' | ||
@model = model | ||
@title = 'New model' | ||
render 'new' | ||
else | ||
flash 'info', 'Model created' | ||
redirect path_to.models | ||
|
||
action 'index', -> | ||
Model.allInstances (error, models) => | ||
@models = models | ||
@title = 'Models index' | ||
render() | ||
|
||
action 'show', -> | ||
@title = 'Model show' | ||
render() | ||
|
||
action 'edit', -> | ||
@title = 'Model edit' | ||
render() | ||
|
||
action 'update', -> | ||
@model.save req.body, (error, model) => | ||
if error | ||
flash 'error', 'Model can not be updated' | ||
@title = 'Edit model details' | ||
render 'edit' | ||
else | ||
flash 'info', 'Model updated' | ||
redirect path_to.model(@model) | ||
|
||
action 'destroy', -> | ||
@model.destroy (error, success) -> | ||
if error | ||
flash 'error', 'Can not destroy model' | ||
else | ||
flash 'info', 'Model successfully removed' | ||
send "'" + path_to.models + "'" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
before(loadModel, {only: ['show', 'edit', 'update', 'destroy']}); | ||
|
||
action('new', function () { | ||
this.title = 'New model'; | ||
this.model = new Model; | ||
render(); | ||
}); | ||
|
||
action('create', function () { | ||
Model.create(req.body, function (error, model) { | ||
if (error) { | ||
flash('error', 'Model can not be created'); | ||
render('new', { | ||
model: model, | ||
title: 'New model' | ||
}); | ||
} else { | ||
flash('info', 'Model created'); | ||
redirect(path_to.models); | ||
} | ||
}); | ||
}); | ||
|
||
action('index', function () { | ||
this.title = 'Models index'; | ||
Model.allInstances(function (error, models) { | ||
render({ | ||
models: models, | ||
}); | ||
}); | ||
}); | ||
|
||
action('show', function () { | ||
this.title = 'Model show'; | ||
render(); | ||
}); | ||
|
||
action('edit', function () { | ||
this.title = 'Model edit'; | ||
render(); | ||
}); | ||
|
||
action('update', function () { | ||
this.model.save(req.body, function (error, model) { | ||
if (error) { | ||
flash('error', 'Model can not be updated'); | ||
this.title = 'Edit model details'; | ||
render('edit'); | ||
} else { | ||
flash('info', 'Model updated'); | ||
redirect(path_to.model(this.model)); | ||
} | ||
}.bind(this)); | ||
}); | ||
|
||
action('destroy', function () { | ||
this.model.destroy(function (error, success) { | ||
if (error) { | ||
flash('error', 'Can not destroy model'); | ||
} else { | ||
flash('info', 'Model successfully removed'); | ||
} | ||
send("'" + path_to.models + "'"); | ||
}); | ||
}); | ||
|
||
function loadModel () { | ||
Model.findById(req.params['id'], function (error, model) { | ||
if (error) { | ||
redirect(path_to.models); | ||
} else { | ||
this.model = model; | ||
next(); | ||
} | ||
}.bind(this)); | ||
} |