Skip to content

Instantly share code, notes, and snippets.

@arbarlow
Created February 15, 2012 20:30
Show Gist options
  • Select an option

  • Save arbarlow/1838796 to your computer and use it in GitHub Desktop.

Select an option

Save arbarlow/1838796 to your computer and use it in GitHub Desktop.
exports.create = function(req, res){
var product = Models.Product.build(req.body);
var errors = product.validate();
if (!errors) {
var image = req.files.image;
product.image = image.name;
console.log(image);
fs.rename(image.path, './public/images/1.jpg', function(err){
product.save().success(function() {
res.redirect('/products');
});
});
}else{
var form = new Formed(product, '/products', {id: 'new_product_form', "enctype": "multipart/form-data"}, errors);
res.render('products/new', {form: form});
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment