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

  • Home
  • SEARCH
  • 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 7699777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:33:31+00:00 2026-05-31T22:33:31+00:00

In Rails 3.0.9 (Ruby 1.9.2, MySQL) I have a method that is supposed to

  • 0

In Rails 3.0.9 (Ruby 1.9.2, MySQL) I have a method that is supposed to find users using two fields, type(string) and flag(boolean). The string part of the query works fine, but not the boolean part.

here’s the code:

def find_users(type)
  @private_users = User.where('type =? and flag != ?', org_type, true)
end

to try to figure out what’s going on, put this code:

@users.each do |f|
  puts "oh helllllllllllllllllllllllllllo #{f.user_name}"      
  puts "oh helllllllllllllllllllllllllllo #{f.flag}" 
  puts "oh helllllllllllllllllllllllllllo #{f.type}"
end

The flag field is blank/null for most of these and those are the ones I’m trying to pick up.

If I change the expression to ('type =? and flag = ?', type, true), it correctly finds the ones where 1 is the value of the flag.

I’ve tried these things to no avail:

 User.where('type =? and flag = ?', org_type, false)
 User.where('type =? and flag = ?', org_type, "")
 User.where('type =? and flag = ?', org_type, nil)

This probably an easy question for someone, so I hoping some knows the answer. Thank you!

  • 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-05-31T22:33:32+00:00Added an answer on May 31, 2026 at 10:33 pm

    Try

    User.where(:type => org_type, flag: nil)
    

    Should result in the SQL query

    SELECT "users".* FROM "users" WHERE "users"."type" = 'some_type' AND "users"."flag" IS NULL
    

    The key being that ActiveRecord will use the IS NULL operator for your flag column.

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

Sidebar

Related Questions

I am using ruby on rails with a MySQL backend. I have a table
I'm using Rails 3.0.3, and I have changed the mysql adapter from ruby-mysql to
I have Ruby on Rails application which is using MySQL database. For now I'm
I am used to using changed_at fields in my MySQL database that Ruby on
I am using Ruby on Rails and have a situation that I am wondering
Hello Ruby/Rails/Merb developers! Im currently working on a web project that will have a
I have a couple of scripts that interact with a MySQL database using ActiveRecord
I have an app that I'm porting from PHP/symfony to Ruby/Rails. Though the language
I have developed a fully functional ruby-on-rails application which utilizes numerous mysql tables. I
I have migrated a old php/mysql site to ruby on rails, and had to

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.