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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:52:40+00:00 2026-05-21T05:52:40+00:00

I have a user model like this: class User < ActiveRecord::Base validates :password, :presence

  • 0

I have a user model like this:

class User < ActiveRecord::Base
    validates :password, :presence => true,
                         :confirmation => true,
                         :length => { :within => 6..40 }
    .
    .
    .
end

In the User model, I have a billing_id column I want to save into from a OrdersController which looks like this:

class OrdersController < ApplicationController
    .
    .
    .
    def create
        @order = Order.new(params[:order])
        if @order.save
            if @order.purchase
                response = GATEWAY.store(credit_card, options)
                result = response.params['billingid']
                @thisuser = User.find(current_user)
                @thisuser.billing_id  = result
                if @thisuser.save
                        redirect_to(root_url), :notice => 'billing id saved')
                    else
                        redirect_to(root_url), :notice => @thisuser.errors)
                    end
            end
        end
    end

Because of validates :password in the User model, @thisuser.save doesn’t save. However, once I comment out the validation, @thisuser.save returns true. This is an unfamiliar territory for me because I thought this validation only worked when creating a new User. Can someone tell me if validates :password is supposed to kick in each time I try to save in User model? Thanks

  • 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-21T05:52:41+00:00Added an answer on May 21, 2026 at 5:52 am

    You need to specify when you want to run your validations otherwise they will be run on every save call. This is easy to limit, though:

    validates :password,
      :presence => true,
      :confirmation => true,
      :length => { :within => 6..40 },
      :on => :create
    

    An alternative is to have this validation trigger conditionally:

    validates :password,
      :presence => true,
      :confirmation => true,
      :length => { :within => 6..40 },
      :if => :password_required?
    

    You define a method that indicates if a password is required before this model can be considered valid:

    class User < ActiveRecord::Base
      def password_required?
        # Validation required if this is a new record or the password is being
        # updated.
        self.new_record? or self.password?
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a TakeAction model that looks like this: class TakeAction < ActiveRecord::Base belongs_to
Given a user model something along the lines of: class User < ActiveRecord::Base acts_as_authentic
So I have a User model that :has_many other models like Documents, Videos, Posts
I have a data model that includes common columns like addedBy, editedby (user), addedDate,
In my user model, I have an attribute called nickname and validates as such:
I have the following two models: class Product < ActiveRecord::Base belongs_to :shop validates_numericality_of :price,
So I have the basics setup already. This is my User model: # ==
In my project, I have a self-referential association. I have a User model: class
For example, if I have a user model and I need to validate login
I have a model Foo which have a ForeignKey to the User model. Later,

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.