title: Default boolean value not being set Rails 4 Postgres
body: <p>I have created a migration to my users table with the following code:</p>
  
  <pre><code>add_column :users, :email_confirmed, :boolean, :default =&gt; false
  </code></pre>
  
  <p>however when a new user is created the <code>:email_confirmed</code> field is automatically set to <code>true</code>. Has this happened to anyone? Am I missing something simple? Any insights are welcome.</p>
  
  <p>My User model:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
      has_many :microposts, dependent: :destroy
    has_many :relationships, foreign_key: "follower_id", dependent: :destroy
    has_many :followed_users, through: :relationships, source: :followed
    has_many :reverse_relationships, foreign_key: "followed_id",
                                     class_name:  "Relationship",
                                     dependent:   :destroy
    has_many :followers, through: :reverse_relationships, source: :follower
      has_secure_password
      before_save { email.downcase! }
    VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(?:\.[a-z\d\-]+)*\.[a-z]+\z/i
      before_create :create_remember_token
    before_create :confirmation_token
    validates :name, presence: true, length: { maximum: 50 }
        validates :email, presence: true, 
          format: { with: VALID_EMAIL_REGEX }, 
                uniqueness: { case_sensitive: false }
        validates :password, length: { minimum: 6 }, :unless =&gt; :email_activate
  
    def feed
       Micropost.from_users_followed_by(self)
    end
  
    def following?(other_user)
      relationships.find_by(followed_id: other_user.id)
    end
  
    def follow!(other_user)
      relationships.create!(followed_id: other_user.id)
    end
  
    def unfollow!(other_user)
      relationships.find_by(followed_id: other_user.id).destroy
    end
  
    def User.new_remember_token
      SecureRandom.urlsafe_base64
    end
  
    def User.digest(token)
      Digest::SHA1.hexdigest(token.to_s)
    end
  
    def email_activate
      self.email_confirmed = true
      save!(:validate =&gt; false)
    end
  
    def send_password_reset
        self.password_reset_token = SecureRandom.urlsafe_base64.to_s
        self.password_reset_sent_at = Time.zone.now
        save!(:validate =&gt; false)
        UserMailer.password_reset(self).deliver
    end
  
    private
  
      def create_remember_token
        self.remember_token = User.digest(User.new_remember_token)
      end
  
      def confirmation_token
        # only generate if you did not manually set value
        if self.confirm_token.blank?
            self.confirm_token = SecureRandom.urlsafe_base64.to_s
        end
      end
  end
  </code></pre>
  
  <p>and my Users Controller:</p>
  
  <pre><code>class UsersController &lt; ApplicationController
    before_action :signed_in_user, only: [:index, :edit, :update, :destroy, :following, :followers]
    before_action :correct_user,   only: [:edit, :update]
    before_action :admin_user,     only: :destroy
    before_action :registered_already, only: [:new, :create]
  
    def index
      @users = User.paginate(page: params[:page])
    end
  
    def show
      @user = User.find(params[:id])
      @microposts = @user.microposts.paginate(page: params[:page])
    end
  
    def new
        @user = User.new
    end
  
    def create
          @user = User.new(user_params)    
        if @user.save
          UserMailer.registration_confirmation(@user).deliver
          flash[:success] = "Please confirm your email address to continue"
          redirect_to root_url
        else
          flash[:error] = "Ooooppss, something went wrong!"
          render 'new'
        end
    end
  
    def edit
    end
  
    def update
      if @user.update_attributes(user_params)
        flash[:success] = "Profile updated"
        redirect_to @user
      else
        render 'edit'
      end
    end
  
    def destroy
      user = User.find(params[:id])
      unless current_user?(user)
        user.destroy
        flash[:success] = "User deleted."
      end
      redirect_to users_url
    end
  
    def following
      @title = "Following"
      @user = User.find(params[:id])
      @users = @user.followed_users.paginate(page: params[:page])
      render 'show_follow'
    end
  
    def followers
      @title = "Followers"
      @user = User.find(params[:id])
      @users = @user.followers.paginate(page: params[:page])
      render 'show_follow'
    end
  
    def confirm_email
      user = User.find_by_confirm_token(params[:id])
      if user
        user.email_activate
        flash[:success] = "Welcome to the Sample App!"
        redirect_to root_url
      else
        flash[:error] = "Sorry. User does not exist"
        redirect_to root_url
      end
    end
  
     private
  
      def user_params
        params.require(:user).permit(:name, :email, :password,
                                     :password_confirmation)
      end
  
      # Before filters
  
      def correct_user
        @user = User.find(params[:id])
        redirect_to(root_url) unless current_user?(@user)
      end
  
      def admin_user
        redirect_to(root_url) unless current_user.admin?
      end
  
      def registered_already
        redirect_to root_url, notice: "You are already registered." if signed_in?
      end
  
  end
  </code></pre>
  
  <p>my Sessions Controller</p>
  
  <pre><code>class SessionsController &lt; ApplicationController
  
    def new
    end
  
    def create
        user = User.find_by_email(params[:email].downcase)
        if user &amp;&amp; user.authenticate(params[:password])
        if user.email_confirmed
            sign_in user
          redirect_back_or user
        else
          flash.now[:error] = 'Please activate your account by following the 
          instructions in the account confirmation email you receieved to proceed'
        end
        else
          flash.now[:error] = 'Invalid email/password combination' # Not quite right!
          render 'new'
        end
    end
  
    def destroy
      sign_out
      redirect_to root_url
    end
  end 
  </code></pre>
  
  <p>I have a feeling that the email_activate method in the users model is being called on the create action but I don't know why?....</p>
  
  <p>Just while I was doing this I commented out the `:unless => :email_activate' in the password validator. Now everything works. I am surprised that this was the reason as it does not make logical sense to my (admittedly somewhat limited) understanding of rails. Could someone explain why this was setting the email confirmed field to true please?</p>