Rails 1.2 routes question

  1. Why not just use the already declared index method?

  2. If you really have to have an additional list method, just add

:collection => {:list => :get} # Presuming you’re gonna use GET to “get” the page/resource

to your mapping for that resource.

But I’d seriously question the need for both an index and a list method. That’s where people are going to land normally based on the common assumptions that most routing uses. http://domain.com/controller == http://domain.com/controller/index. So you’re either going to risk reduplication [index == list] or redirection. Either way sounds like unnecessary work. Yuck.

I can see cases where you might want to use this methodology of a separate list method but not for regular cases. And certainly not just because the old scaffolding used that method. Ick. Scaffolding.

Excuse my snottiness. I have a cold. :wink:

RSL

So if i had a action called 'list' then what is the best way to let routes.rb know to except requests of http://localhost:3004/articles/list

Using REST, you can write the url: http://localhost:3004articles and that will invoke the index method, which would be your list method.

To create a link from a view, you would use: articles_path

And in your routes.rb file you'd declare each RESTful controller: map.resources :articles as you are already, and add a new declaration for each controller.

I found the tutorial as Peep Code very useful.

If you still want to use the /articles/list url, you would set the route something like:   map.connect ':controller/:action/'

using :collection => { :search => :get } in your map.resource declaration in the routes.rb file is the correct way to add custom actions to your routes.

Like this:

map.resources :zip_codes, :collection => { :search => :get }

Controller:   # GET /zip_codes;search   # GET /zip_codes.xml;search   def search   end

The URL would be something like: http://domain.com/articles;search

Just like using some of the standard resource routes like for edit: http://domain.com/articles;edit

By the way there are also ways to add routes for singular and new resources like this:

Singular route: map.resources :articles, :member => { :embargo => :put, :release => :put }

New Route: map.resources :articles, :new => { :shortform => :post }

Sorry, I forgot that part.

Do so like this: <%= link_to search_articles_path %>