tower-archive / tower

UNMAINTAINED - Small components for building apps, manipulating data, and automating a distributed infrastructure.
http://tower.github.io
MIT License
1.79k stars 120 forks source link

Simple blog app #363

Closed vraptor75011 closed 11 years ago

vraptor75011 commented 11 years ago

Could anyone post the code for a simple Blog app (Post + Comments) ? I m having a lot of trouble to figure how to write the controllers, views, templates of Post hasMany comments, Comment belongsTo Post

I also dont understand why we can t create Comment like : /posts/:id/comments/new ?

I would appreciate any help on this.

lancejpollard commented 11 years ago

Does /posts/:postId/comments/new work instead? Then you access the App.Post in the comments controller like this:

new: ->
  App.Post.find @params.postId, (error, post) =>
    # ...
vraptor75011 commented 11 years ago

Sorry, spent 2 days playing with Towerjs and unable to get any results.

edubkendo commented 11 years ago

@vraptor75011 this isn't a simple blog app, but this is a pretty detailed tutorial that will carry you a long way: http://nodehed.com/?p=15

vraptor75011 commented 11 years ago

Already went thru the 5 parts of this tutorial and the repo Ircbot. Could not find answers to my simple questions. Starting from scratch

tower new TowerBlog tower generate scaffold User name:string hasMany:posts tower generate scaffold Post title:string belongsTo:user cake build && node server

First I create a user, then I do this

http://0.0.0.0:3000/users/50c82d654adea12eb0000001/posts, gives "No path matches /users/50c82d654adea12eb0000001/posts" http://0.0.0.0:3000/users/50c82d654adea12eb0000001/posts/new, gives "No path matches /users/50c82d654adea12eb0000001/posts/new"

I tried to write controllers either on server or client side and couldn't get this behavior.

If I nest the resources like this

Tower.Route.draw -> @resources 'users', -> @resources 'posts'

http://0.0.0.0:3000/users/50c82d654adea12eb0000001/posts, returns to http://0.0.0.0:3000/users/50c82d654adea12eb0000001/ with a null user on the client side, there is a userPosts action/event/controller? which I don t know how to use

I m not trying more complicated at the moment. Just want to create a user, create posts that belongs to him.

Fairly simple in Rails, but here, I get stuck ...

edubkendo commented 11 years ago

@viatropos yeah, can't get this to work either. Was gonna put together an example for him, but nothing I'm trying here gets anything to work. Any attempts to visit /posts/:postId/comments/new or any variation on that and it just takes me back to a screwed up version of /posts/:postId/ with all the info missing. The relationships definitely work, because I can manipulate those from the console all I want, or even customize the existing pages to display the desired information, but there's no way to get there via url. Of course, since the router will be changing soon, this may all be moot, but anyways, that's what I arrived at after about an hour of trying to get it working.

@vraptor75011 sorry, yeah, this seems to be broken right now, at least for me.

thehydroimpulse commented 11 years ago

@edubkendo I'm pretty sure it was in a previous issue where nested routes didn't work. That's why people started sending PR for the client-side router trying to fix it, and now were basically restarting the router.

maedi commented 11 years ago

So the Tower devs are rebuilding the Router and other aspects of Tower at the moment. Looks like this will have to wait until the new Router is in place etc.