How would you implement a method that searches a table based on the requesting model?
I've got a User and Vehicle table which are both assigned equipment stored in an Equipment table. I'm trying to show the equipment assigned to a User and Vehicle using the same method. The Equipment table has a user_id and vehicle_id showing where equipment is assigned to.
Is there any way to pass in a table variable (which would be either user or vehicle) and then have that variable_id: as the search criteria in order to either show equipment assigned to a user or vehicle depending on which show page is being viewed-
def equip(table, id)
equip = Equipment.where(table_id: id)
end
such that the table variable passed in replaced the "table" piece of the where() method, making it either user_id or vehicle_id?