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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:17:33+00:00 2026-05-23T10:17:33+00:00

I am encountering a problem which I have never encountered before. I am working

  • 0

I am encountering a problem which I have never encountered before. I am working on code that was written by another programmer and it is kind of a mess.

Here is the problem. I have the following validations in the my model :

validates_presence_of :subscription_level,
                      :message => 'please make a selection'
validates_presence_of :shipping_first_name
validates_presence_of :shipping_last_name
validates_presence_of :shipping_address
validates_presence_of :shipping_city
validates_presence_of :shipping_state
validates_presence_of :shipping_postal_code
validates_presence_of :shipping_country
validates_presence_of :billing_first_name
validates_presence_of :billing_last_name
validates_presence_of :billing_address
validates_presence_of :billing_city
validates_presence_of :billing_state
validates_presence_of :billing_postal_code
validates_presence_of :billing_country
validates_presence_of :card_number
validates_numericality_of :card_number
validates_presence_of :card_expiration_month
validates_numericality_of :card_expiration_month
validates_presence_of :card_expiration_year
validates_numericality_of :card_expiration_year
validates_presence_of :card_cvv
validates_numericality_of :card_cvv

I have two actions for the controller in question. One is new and the other is redeem.
I want to perform all of these validations with the new action but want to skip most of them for redeem action.

The problem I am facing right now is that using valid? in the controller is also validating things which are not required for redeem action.

How can I get around this?

  • 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-23T10:17:34+00:00Added an answer on May 23, 2026 at 10:17 am

    It’s hacky, but I’ve had to resort to having an attribute flag that can enable/disable validations in certain states. (My specific example was a multi-page form, where we eventually want to validate all required fields for an object, but we only can validate data that has been submitted on previous pages)

    Here’s an example of how that might look:

    class Whatever < ActiveRecord::Base
      attr_accessor :enable_strict_validation
    
      validates_presence_of :name # this always happens
      validates_uniqueness_of :name, :if => :enable_strict_validation
    end
    

    Then somewhere else (eg your controller), you can do:

    @whatever = Whatever.new(...)
    @whatever.save  # <= will only run the first validation
    
    @whatever.enable_strict_validation = true
    @whatever.save  # <= will run both validations
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ModelForm in my Django app that uses a forms.ModelMultipleChoiceField, which displays
I'm writing some mail-processing software in Python that is encountering strange bytes in header
I have a web interface to a system which has a left navigation. On
I'm a beginner and this is my first time encountering problem like this. I'm
I have a problem. I want to copy a caption of a label from
I've been encountering an OverflowException recently within GDI+ via a 3rd party tool which
I recently installed Ubuntu Jaunty and I'm encountering a problem when I try to
I am encountering a strange problem when attempting to execute a DELETE query agains
I have the following problem. I have two classes, in this case A and
I'll preface this question with the note that I have looked at this similar

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.