So, I am creating an application that is appropriate for users. Custom models have 3 attributes (which are relevant to my question anyway: gender:string , looking_for_men:boolean , looking_for_women:boolean .
I currently have a method in my model, for example:
def browse if self.looking_for_men == true && self.looking_for_women == true if self.sex == "Male" User.where("looking_for_men = ?", true) elsif self.sex == "Female" User.where("looking_for_women = ?", true) end elsif self.sex == "Male" && self.looking_for_men == true User.where("looking_for_men = ? AND sex = ?", true, "Male") elsif self.sex == "Female" && self.looking_for_women == true User.where("looking_for_women = ? AND sex = ?", true, "Female") else if self.sex == "Male" User.where("looking_for_men = ? AND sex = ?", true, "Female") elsif self.sex == "Female" User.where("looking_for_women = ? AND sex = ?", true, "Male") end end end
This is pretty dirty, as you can tell. Is there anyway to clear this and turn it into a sphere, so let's say, for example, Iām a man-man and Iām looking for women that he returns only women who are looking for men when I make such a request:
@users = User.all.browse
source share