I want a routes like:
get '/posts/new' => 'posts#new'
get '/:username/posts/:id' => 'posts#show'
get '/:username/posts' => 'posts#index'
Accessible via helpers like:
new_post_path #=> new -
post_path(post) #=> show - :username implied from post
posts_path #=> index - :username implied from session
posts_path(user) #=> index - :username explicit
I'd like to do this with resourceful semantics, instead of specifying each route by hand. Also I'm not sure how to make the url helpers smart.
Thoughs?
I'm assuming what you want is to have nested routes. This should get you closer to what you're looking for.
in your routes.rb file:
This will make paths like this:
Then you can tweak your routes from there so that
/posts/new
points to your posts controller with something like this:(untested and not sure this is 100% correct so someone please chime in)