Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I currently have the following models and am designing search functionality that searches within these 3 models: Locations Users User_friends

Should I create a search controller or should I put the action in one of the existing locations, users, or user_friends controllers? If so should it be pluralized - searches_controller or just search_controller?

share|improve this question
up vote 1 down vote accepted

Would depend on a few details about your search options. Our website has rather complex search options (using Apache Solr to search over articles that have a heavy load of facets like categories, technical properties etc.).

I have actually two search controllers, one for customers (basic search functionality) and one in the admin section that handles some more complicated internal queries.

The outward bound controller is named search_controller and has only a show action. Mostly because the text input that triggers the search is available from everywhere on the site, so you can do only a single "search". (I'm not 100% happy with this singular naming here and may change it)

The admin variant is called searches_controller and has an index action and a show action. The index action will display a page with all the search options. This then triggers the show action to display search results.

If there is any doubt, I would more likely go with the plural variation, it's just more simple. index giving the options, show displays the results. (though using new for the options would maybe make sense too)

Since you search over multiple tables a dedicated searches_controller most likely makes sense, though if one of the models is the "main" model, you could as well use this models index action if this isn't already taken. If you would start to add non REST actions, it's a sign that a controller makes sense (not mandatory of course)

The work load to actually search belongs in the models or some library.

share|improve this answer

I'd create a Searches controller, but perform the query in the models.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.