Skip to content

Instantly share code, notes, and snippets.

@beautyfree
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beautyfree/2179af58575a0f0cc50c to your computer and use it in GitHub Desktop.
Save beautyfree/2179af58575a0f0cc50c to your computer and use it in GitHub Desktop.
Sails.js controller like rails
/**
* Admin/content/cardController
*
* @description :: Server-side logic for managing admin/content/cards
* @help :: See http://links.sailsjs.org/docs/controllers
*/
module.exports = {
index: function (req,res) {
Card.find().exec(function(err, cards) {
res.view({cards: cards});
});
},
new: function (req,res) {
res.view();
},
edit: function (req,res) {
var id = req.param("id",null);
Card.findOne(id).exec(function(err, card) {
res.view({card: card});
});
},
create: function (req,res) {
Card.create(req.param("Card")).exec(function(err,card) {
if (err) return res.send(500);
//res.send("Successfully Created!");
res.redirect('admin/content/card/edit/'+card.id);
});
},
update: function (req, res) {
var id = req.param("id",null);
Card.update(id, req.param("Card")).exec(function (err) {
if (err) return res.send(500);
res.redirect('admin/content/card/edit/'+id);
});
},
delete: function (req, res) {
var id = req.param("id",null);
Card.destroy(id).exec(function (err) {
if (err) return res.send(500);
res.redirect('admin/content/card/');
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment