What I'm trying to do:
I'm building a system where there are different types of post. Setting aside the models, this question is about the routes and the controller
Basically /posts/new
should go to an index page of sorts, while /posts/new/anything
should look up the type anything
and then build a form for creating a new one.
How I'm trying to do it:
Feel free to ignore this section as I could be completely on the wrong track.
In the routes config:
map.connect '/posts/new', :controller => 'posts', :action => 'new_index'
map.resources :posts, :path_names => { :new => 'new/:type' }
In the controller:
class PostsController
# implicit: def new_index ; end
def new
@post = class_for_type(params[:type]).new
end
end
The view has code which looks at the type of @post to determine which set of views to use. Turns out this gets me 90% of the way there: /posts/new/quip
does actually send me to the correct page to create a quip, and so forth. /posts/new
does send me to an index page.
Problem is twofold.
I still want to have convenience methods like this:
<%= link_to 'New Post', new_post_path %>
But this is now invalid as
new_post_path
requires the:type
parameter.I would like to do it using one route if possible.