Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9023115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:41:04+00:00 2026-06-16T05:41:04+00:00

This is somewhat of an updated question from a problem I had earlier. I

  • 0

This is somewhat of an updated question from a problem I had earlier. I am creating a ‘match.com’ style app for local dog adoptions, where users and dogs have a profile. In each profile, there are Boolean fields. I am trying to show the end user only the dogs that match their user profile. A simple one-to-one match does not work however since the logic changes depending on the user’s Boolean. For example, if a user has kids (user.kids_under_10: true) then I simply match it to a dog that can be placed with kids (dog.kids_under_10:true). The model would look like

class Dog < ActiveRecord::Base

def self.by_profile(user)
  if user.kids_under_10 == true
    Dog.where(kids_under_10: user.kids_under_10)
  end
end

If the user does not have kids however, dogs that answer both true and false to this question can be displayed, since dogs that are AND are not kid friendly can be placed with this user. I realize that if this were the only criteria for matching, I could simply add a else, Dog.all statement to the above method. Since there will other Boolean fields to match however (i.e. user.has_cats and dog.cat_friendly), this solution would not work. I think I need a variable containing an array here, but not really sure… any suggestions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:41:06+00:00Added an answer on June 16, 2026 at 5:41 am

    So I found a solution, however I ‘m not sure it’s the most efficient solution, so any suggestions are very welcome (I am new to programming and looking to learn the ‘best’ way to handle different situations). Here is how I solved the issue:

    class Dog < ActiveRecord::Base
    
    def self.by_profile(user)
      if user.kids_under_10?
        kids_under_10 = true
      else
        kids_under_10 = [true, false]
      end
    
      Dog.where(kids_under_10: kids_under_10)
    end
    end
    

    I can foresee this solution becoming a bit cumbersome as I add more parameters. The conditional statements could get quite long. Thanks for any suggestions!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Updated: This is an update to my previous question that was somewhat off topic
somewhat related to: libxml2 from java yes, this question is rather long-winded - sorry.
this is somewhat of an odd question. I wrote a C function. Its 'like'
This is somewhat similiar to this : pthread function from a class But the
This is somewhat related to the question posed in this question but I'm trying
This is somewhat of a newbie question I'm sure and I hope the community
I have a somewhat ridiculous question regarding DDD, Repository Patterns and ORM. In this
Apologies if this is somewhat of a duplicate question, I did see others but
My issue is somewhat similar to this SO question. However, since my implementation is
This question is somewhat an illustration to a related post , I believe the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.