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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:47:28+00:00 2026-05-31T19:47:28+00:00

I have this validation validates :contact_id, :presence => true, :uniqueness => {:message => ‘has

  • 0

I have this validation

 validates :contact_id, :presence => true, :uniqueness => {:message => 'has an account already.'}

in the application.rb model

All is good but I need to only do this validation if the state is “invalid”

For example in the applications table there is a field called state and if there is a application with a contact_id of a user and the state is “invalid” then this validation should not take effect and should let the user save the application

  • 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-31T19:47:28+00:00Added an answer on May 31, 2026 at 7:47 pm

    I believe this should do it:

    validates :contact_id,
        :presence => true,
        :uniqueness => {:message => 'has an account already.'},
        :if => :invalid?
    
    def invalid?
        state == 'invalid'
    end
    

    you could also inline that to:

    validates :contact_id,
        :presence => true,
        :uniqueness => {:message => 'has an account already.'},
        :if => lambda{ state == 'invalid' }
    

    Hope this helps.

    If you are going to do it when the state is not invalid, then you could do that two ways:

    validates :contact_id,
        :presence => true,
        :uniqueness => {:message => 'has an account already.'},
        :unless => :invalid?
    

    Or you could change it a bit more and have a valid message, which I might prefer:

    validates :contact_id,
        :presence => true,
        :uniqueness => {:message => 'has an account already.'},
        :if => :valid?
    
    def valid?
        state != 'invalid'
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This one really has me. I have this validation in my user model: validates
I have the following validation: validates :password, :presence => true, :confirmation => true, :length
I have a rails model with this validation: validates_numericality_of(:insert_oz, :allow_blank=>true, :greater_than=>0, :if=>(proc do |note|
I have the following validation rule on one of the models, validates :reciept_num, :presence
For example I have a css style like this : input.validation-passed {border: 1px solid
I have no idea why this doesn't work, but doing some validation functions and
I have this idea for a free backup application. The largest problem I need
I have this form that validates the fields on submit through ajax (using Codeigniter's
I have the following validation: validates_format_of :title, :with => /^[A-Z0-9 áàâäãçéèêëíìîïñóòôøöõúùûüý'-.]*$/i, :message => must
In my application I have 1 field name contact_no,in that i want validation like

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.