John M. wrote:
Since I’ve been learning rails, I thought that routes are the linking of
the “Controller” Object to their “Action” method.
When you set up RESTful routing, you need to add custom or named routes
after the default 7.
I tend to think of it as adding them ‘inline’
As Rob suggested:
Combine those into:
map.resources :projects, :collection => { :view_all => :get }
The above line gets you the default routes, and adds a route that works
on the projects collection called ‘view_all’ and is a GET request. Just
what your view_all route will do is up to the controller code for that
method, but we assumed that you’re returning all the projects, which is
what ‘index’ does.
Hence my earlier point that your ‘show_all’ is functionally the same as
the default ‘index’, and unnecessary…
There is also the ability to add routes that deal with a specific
project. You’d specify this type of route using the :member
specification.
map.resources :projects, :member => {:as_pdf => :get}
This route is intended to operate against a single project, and is a GET
request.
My app has a project model as well, and it’s map.resources line looks
like this:
map.resources :projects, :member => {:as_pdf => :get, :clone => :get,
:trace => :get}
This yields the index, show, new, create, edit, update, and destroy
standard routes, as well as:
an ‘as_pdf’ route (to generate a pdf of the project info),
a ‘clone’ route (makes a deep clone of an existing project), and
a ‘trace’ route which generates a traceability view of the project)
Run a rake routes >routes.lst command from the root of your app, then
look insude routes.lst to see what’s being generated for you by restful
routing. It’s very informative.