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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:58:54+00:00 2026-06-15T14:58:54+00:00

I have the following (simplified) model and migration: Model: class User < ActiveRecord::Base attr_readonly

  • 0

I have the following (simplified) model and migration:

Model:

class User < ActiveRecord::Base
  attr_readonly :contacted

  validates :contacted, :inclusion => { :in => [true, false] }

  def set_contacted
    self.contacted = true
  end

  def unset_contacted
    # self.contacted = false
    self.contacted = "0"
  end
end

Migration:

class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
      t.boolean :contacted,     :null => false, :default => false

      t.timestamps
    end
  end
end

As you can kind of see in the comment in my model, setting the variable contact to false results in an error – I can only set it to “0”. Why? I don’t see how “false” would violate the null constraint, right?

Edit:
For clarification, I am using PostgreSQL and ActiveRecord. The error that I’m getting is this:

C:/Ruby193/lib/ruby/gems/activerecord-3.2.8/lib/active_record/validations.rb:56:in 'save!' Validation failed: ActiveRecord::RecordInvalid)

I get that error even if I remove the “validates” statement from my model, and even if I remove the NULL constraint from the migration. It’s something to do with setting the value of the attribute to be false. Is there some odd constraint on ActiveRecord booleans?

  • 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-15T14:58:55+00:00Added an answer on June 15, 2026 at 2:58 pm

    No one seems able to solve this, but it’ no longer an issue for me. My model is better served by using a state_machine gem, so I removed this field altogether.

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

Sidebar

Related Questions

I have the following User model on my application (simplified) class User < ActiveRecord::Base
I have the following (heavily simplified) model, that uses will_paginate class Search < ActiveRecord::Base
I have the following model in rails (simplified): class Phone < ActiveRecord::Base include ActiveModel::Validations
I have the following simplified model: class User attr_accessible :password validates :password, :presence =>
I have the following - simplified - models: class User(models.Model): following = models.ManyToManyField(self, through='Following',
Lets say we have the following models: (simplified) class Collection(models.Model): slug = models.SlugField() class
I have the following model class (simplified) class A{ private String name; private List<B>
I have the following model (greatly simplified for the purposes of this question): class
I have the following (simplified) models: class School(models.Model): name = models.CharField(max_length=128) class UserProfile(models.Model): school
I have the following model (simplified): abstract class CartItem { EntityReference<Cart> Cart; } class

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.