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 7966397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:24:56+00:00 2026-06-04T06:24:56+00:00

In my Rails app, I need to store boolean fields in a model. Now,

  • 0

In my Rails app, I need to store boolean fields in a model. Now, this causes a problem since Sqlite3 (which I use for development) uses the character constants 't' and 'f' for truth values. MySQL however, to which my app will be deployed, uses the literals true and false (corresponding to tinyints 1 and 0 respectively). This makes the use of SQL conditions problematic, since an expression of the type

select * from articles where published = true

expressed in Rails as

Article.where 'published = true'

will fail in Sqlite3 with the message no such column: true.

What is the preferred way to handle booleans adapter-portably in Rails?

  • 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-04T06:24:57+00:00Added an answer on June 4, 2026 at 6:24 am

    Using active record, you would do

    Article.where(:published => true)
    

    You would probably want to take this a step further, and make this a scope

    class Article < ActiveRecord::Base
      scope :published, where(:published => true)
    end
    

    So that in your controller you can just go

    @published_articles = Article.published
    

    More information on active_record’s query interface here: http://guides.rubyonrails.org/active_record_querying.html

    You are also using an assignment operation = instead of equality comparison ==

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

Sidebar

Related Questions

I need a 6 character alphanumeric ID for use in my rails app, which
So I need to access this service from my rails app. I'm using soap4r
We have the rails app, content served from the database. Now we need to
I need to store app specific configuration in rails. But it has to be:
I need to use a percentage in my Rails app. In any view, including
I need to collect and store mailing addresses in a Rails (2.3) app. Is
I am building a small rails app and I need a way to generate
I need to produce somewhat complicated PDFs from a Rails app - tables with
I need to start a copy of a Rails app from within Java. I
I need to implement fine-grained access control in a Ruby on Rails app. 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.