Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
christiannwamba committed Sep 28, 2016
1 parent 4a217f9 commit 5b01bd7
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 17 deletions.
8 changes: 4 additions & 4 deletions app/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = {
if(err) res.send(err);

res.render('pages/edit', {post: posts[0]});
});
}); 
},
create: function (req, res) {
cloudinary.v2.uploader.upload(req.files.image.path,
Expand Down Expand Up @@ -73,15 +73,15 @@ module.exports = {
},
destroy: function (req, res) {
var imageId = req.body.image_id;
cloudinary.v2.uploader.destroy(imageId, function (result) {
cloudinary.v2.uploader.destroy(imageId, function (error, result) {
Model.findOneAndRemove({ image_id: imageId }, function(err) {
if (err) res.send(err);

res.redirect('/');
});
});
},

admin:{
index: function (req, res) {
var q = req.query.q;
Expand All @@ -100,4 +100,4 @@ module.exports = {
}
}
}
};
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"connect-multiparty": "^2.0.0",
"ejs": "^2.5.2",
"express": "^4.14.0",
"mongoose": "^4.6.0"
"mongoose": "^4.6.0",
"morgan": "^1.7.0"
}
}
14 changes: 14 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Scotchgram

This is a demo tha backs a scotch article on using Cloudinary to build an image backend for your application

## Branches
Each step has a branch to it, so you can checkout to the branch and preview the step's demo.

The master branch has the final example

## Usage

```
```
6 changes: 3 additions & 3 deletions routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ module.exports = function (app) {

app.post('/destroy', controller.destroy);

app.get('/:id', controller.find);
app.get('/account/:id', controller.find);



/*
* Admin Routes
*
* */
app.get('/admin', controller.admin.index);
};
};
5 changes: 3 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
var express = require('express');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var morgan = require('morgan');

var app = express();

app.use(morgan('dev'));
app.use(express.static(__dirname + '/public'));

mongoose.connect('mongodb://127.0.0.1:27017/scotchgram');
Expand All @@ -27,4 +28,4 @@ require('./routes')(app);
var port = app.get('port');
app.listen(port, function () {
console.log('App running at ' + port);
});
});
8 changes: 4 additions & 4 deletions views/admin/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@
</div>
</div>
<div class="extra content">
<form action="/admin/destroy" method="post" style="display: inline" id="destroy_form<%= index %>">
<form action="/destroy" method="post" style="display: inline" id="destroy_form<%= index %>">
<input type="hidden" name="image_id" value="<%= post.public_id %>">
<a onclick="document.getElementById('destroy_form<%= index %>').submit(); return false;">
<i class="remove icon"></i> Remove
</a>
</form>
<a href="/edit/<%= post.public_id %>">
<!-- <a href="/edit/<%= post.public_id %>">
<i class="edit icon"></i> Edit
</a>
</a> -->
</div>
</div>
</div>
Expand All @@ -66,4 +66,4 @@

<% include ../partials/scripts %>
</body>
</html>
</html>
4 changes: 2 additions & 2 deletions views/pages/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<img src="<%= post.image %>" style="max-height: 150px">
</div>
<div class="content">
<a class="header" href="/<%= post.image_id %>"><%= post.title %></a>
<a class="header" href="/account/<%= post.image_id %>"><%= post.title %></a>
<div class="meta">
<span class="date">
<i class="calendar icon"></i> <%= post.created_at.getFullYear() %>
Expand Down Expand Up @@ -55,4 +55,4 @@

<% include ../partials/scripts %>
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion views/pages/single.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@

<% include ../partials/scripts %>
</body>
</html>
</html>

0 comments on commit 5b01bd7

Please sign in to comment.