Searching database in Rails with multiple optional parameters

I have a Rails app with following schema:

User (id, username, user_type, master_id) Item ( id,itemname,master_id)
Repairs (id, in_date, out_date, user_id, item_id)

The app is small so I have tried keeping db as simple as possible. A
user
can be Admin, Dealer or Manager. A manager can have many dealers under
him(Both stored in same user table).

An Item can be a ‘master item’ like a computer(with many sub items like
keyboard,mouse) or it can be just a small sub item. So a master item can
have many sub items under it.

A repair is Repair history for item. A repair has an item and user
associated with it.

I have a search for with following parameters ( ALl optional)

  • Manager Name
  • Dealer Name
  • Master Item
  • Sub Item
  • In date
  • Out date

If no ‘Dealer Name’ is specified I want results to have all Dealers
under
the specified ‘manager name’ included in results, if no ‘Sub Item’ is
specified I want all items under ‘Master Item’ to be in the results.

How should the search controller be defined so as to keep code simple
and
maintainable? I dont really want to do an ‘if’ for each condition.