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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:33:40+00:00 2026-05-28T04:33:40+00:00

I am using Rails v2.3 If I have a model : class car <

  • 0

I am using Rails v2.3

If I have a model:

class car < ActiveRecord::Base

  validate :method_1, :method_2, :method_3

  ...
  # custom validation methods
  def method_1
    ...
  end

  def method_2
    ...
  end

  def method_3
    ...
  end
end

As you see above, I have 3 custom validation methods, and I use them for model validation.

If I have another method in this model class which save an new instance of the model like following:

# "flag" here is NOT a DB based attribute
def save_special_car flag
   new_car=Car.new(...)

   new_car.save #how to skip validation method_2 if flag==true
end

I would like to skip the validation of method_2 in this particular method for saving new car, how to skip the certain validation method?

  • 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-28T04:33:40+00:00Added an answer on May 28, 2026 at 4:33 am

    Update your model to this

    class Car < ActiveRecord::Base
    
      # depending on how you deal with mass-assignment
      # protection in newer Rails versions,
      # you might want to uncomment this line
      # 
      # attr_accessible :skip_method_2
    
      attr_accessor :skip_method_2 
    
      validate :method_1, :method_3
      validate :method_2, unless: :skip_method_2
    
      private # encapsulation is cool, so we are cool
    
        # custom validation methods
        def method_1
          # ...
        end
    
        def method_2
          # ...
        end
    
        def method_3
          # ...
        end
    end
    

    Then in your controller put:

    def save_special_car
       new_car=Car.new(skip_method_2: true)
       new_car.save
    end
    

    If you’re getting :flag via params variable in your controller, you can use

    def save_special_car
       new_car=Car.new(skip_method_2: params[:flag].present?)
       new_car.save
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using Rails 3.0.3 I have a Model Bill: class Bill < ActiveRecord::Base has_many
I have the following model and methods: class UserPrice < ActiveRecord::Base attr_accessible :price, :purchase_date,
I'm using Rails 3. I have 3 models: class Deal < ActiveRecord::Base has_many :wishes,
I am using Rails 3 and here is my model class LineItem < ActiveRecord::Base
I am using Rails v2.3.2 . I have a model called UsersCar : class
I have the following model: class Advisor < ActiveRecord::Base belongs_to :course end class Course
Note: Using Rails 3.1 and current delayed_job gem. I have a User model that
I am using Devise in Rails 3, and have a User model in rails
I'm using rails 3, and began my application with ActiveRecord. Now, I have many
I am using Rails and ActiveRecord. I have carrierwave mounted on one of 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.