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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:46:17+00:00 2026-06-08T22:46:17+00:00

There is an update of a field I wish to do when saving an

  • 0

There is an update of a field I wish to do when saving an object.
This update must happen whether the object is validated or not,
and must happen before validation.

The problem is that before_validation doesn’t run when saving without validation.
Where should this piece of code reside?
is there a way to call the before_validation callback when saving without validating?

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-06-08T22:46:20+00:00Added an answer on June 8, 2026 at 10:46 pm

    No, according to http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html

    You are hitting this problem because you are being naughty, you are saving without validation. Stop that. Seriously. Instead, you should relax your validation strategy so all this “saving without validation” nonsense, becomes “saving with validation” instead.

    To do that, you can pass some options to validation methods, or have some conditional clauses in a custom validate methods.

    class User < ActiveRecord::Base
      before_validation :my_crazy_thing      
      validates_presence_of :name, :unless => :is_a_robot?
    
      def is_a_robot?
        @brain_type == :positronic
      end
    
      def my_crazy_thing
        @brain_type = brain_surgery.brain_type
        # or whatever
      end
    
      def validate
        if condition_exists_to_run_custom_validations
          errors.add_to_base 'WTF' if @universe.exploded?
        end
      end
    end
    

    So where before, you would have had to skip validation so that robots could exist without a name. But if you setup validations properly, then you never need to save without them. You can tell you’ve set them up properly because you don’t have to save without validating any more. And now you can properly use the before_validation callback all the time as a nice bonus.

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

Sidebar

Related Questions

My problem is that I have to update a field of an object based
Is there any way to update nested documents by id or some other field?
Is there a way to update only Hour part in a DateTime field?? If
Is there any way to perform an update for normalizing a field using a
UPDATE - There are a lot of posts regarding the Child actions are not
My requirement is that I want an object (tee) to update if there have
Is there an equivalent of MySQLs on update field for SQL server? With both
There is a need to update one field to the same value in a
is there possibility to update a new field to an existing document? For example:
I there a way to update a row without mentioning fields name ? I

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.