Configure routes.rb

Just wondering if this is possible and how to configure routes.rb

Let’s say in routes.rb I have:

map.resources :products

this would allow me to use:

new_product_path and the url would be /product/new
edit_product_path and the url would be /product/1/edit

I would like to add another method to the controller that would be
exactly like the “new” method.

my_method_product_path and the url would be /product/my_method

I tried:

map.resources :products, :member => { :my_method => :get}

but, the method wants a parameter like my_method_product_path(0)

How would I configure the routes.rb to accomplish this task??

can you give us more information on what this action is supposed to do?

On Jan 24, 2008 10:04 AM, TheDuckman [email protected] wrote:

edit_product_path and the url would be /product/1/edit
but, the method wants a parameter like my_method_product_path(0)

How would I configure the routes.rb to accomplish this task??


Ryan B.

Feel free to add me to MSN and/or GTalk as this email.

to make a route without parameters don’t use :member.
as ryan says it depends on what you want to do.

it could be :
with a “new” parameter
map.resources :products, :new => { :my_method => :get}
you will call it new_my_method_product_path
or
with a “collection” parameter
map.resources :products, :collection => { :my_method => :get}
you will call it my_method_products_path

I have a related question. I started off with:
map.resources :listings
map.resources :categories

Then I wanted to display listings that belong to a certain category at
“/listings/category”, so I added the following to my routes:
map.resources :listings,
:requirements => { :id => /[0-9]/}
map.abc ‘listings/:id’, :controller => ‘listings’, :action =>
‘show_constrained’
map.abc ‘listings/:id.:format’, :controller => ‘listings’, :action
=> ‘show_constrained’

This is successful in routing requests to the right actions, but it
gives me only one helper method for the named route ‘abc’, which then
becomes a problem for me. Am I going about this the wrong way?