"map.resources :customers" and custom methods

Hi

We're using map.resources :customers to give an external
application access to our customers table. In addition to the
standards methods like index/new/show etc... we would like to
implement some custom methods.

For example one custom method could be the case when you want to
return all customers with a specific lastname instead of just all
customers or one specific customers.

So I implemented a method searchCustomers which takes the respective
lastname param for searching the database. Now that method doesn't
work because rails tries to map the searchCustomer?
customer[lastname]=xy to an ID.

Do I need to have a separate controller for these methods? or am I
missing something

Use the :collection option in map.resources (api.rubyonrails.org). And
consider giving it a better name than searchCustomers.

Rein

So I implemented a method searchCustomers which takes the respective

lastname param for searching the database. Now that method doesn’t

work because rails tries to map the searchCustomer?

customer[lastname]=xy to an ID.

I don’t know if you’d like to approach it the same way I did, but here goes.

I use the index method for my searches. I check if there are search params
in the request, and modify my find accordingly.

Regards,
Franz

Me too. From a REST view it is fine to think about search as getting
the collection of resources (index) scoped by a "search" param.

Agreed.