I’m trying to design a Search controller that will search my social
network website for Friends and Colleagues. However, I would like to
have some kind of encapsulation so that the Friend and Colleagues models
are responsible for performing their own searches, returning the results
to the Search, formatted according to their own separate views.
I think this is the right way to do things because these two different
models would be searching over different columns and returning different
forms of results (Colleagues might have a ‘workplace’, for example).
Also, this would make the system more extensible in the future, if I
need to add a Classmate object etc.
My question is simply, what’s the best way to do this? I am new to Ruby
and Rails, so I am not sure how the classes can interact, how I should
be passing around the search parameters and returning results with
set-specific views. Also I am worried that if both the Friend and
Colleague models are performing the search themselves, this would
violate the DRY principle.
Any help would be much appreciated,