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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:45:51+00:00 2026-06-13T13:45:51+00:00

I am trying to validate that two columns are unique in my User model.

  • 0

I am trying to validate that two columns are unique in my User model. I’ve searched Google and from what I understand the following code will not work:

validates :login, :uniqueness=>true
validates :email, :uniqueness=>true

In my case doing that will validate the uniqueness of email, but will not validate the uniqueness of login. I set that login must be unique on the database. However, all that will do is generate a runtime error if it already exists. I don’t want that error in production because it would result in a 500 internal server error, which the user would not understand.

Any ideas on how I could validate the uniqueness of both of these fields?

Authentication Used:

  • CanCan
  • Devise
  • Devise Invitable

Update:

From what I can tell the problem is being caused by Devise, specifically the validatable module, which validate email and password.

Update 2:

Removing the validatable module from Devise will result in neither checking for uniqueness.

Update 3:

It appears that devise is not causing the problem. Rather, a gem called Devise Invitable is. Removing this gem results in the validation being triggered. It also appears that this gem tries to force validations of the email field. It makes sense due to the nature of this gem, but shouldn’t be blocking.

  • 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-13T13:45:52+00:00Added an answer on June 13, 2026 at 1:45 pm

    The problem was with the devise_invitable gem. In the devise initializer I had to set

      config.validate_on_invite = true
    

    to make sure the validations were executed, the default is false. I also had to remove the devise validatable module.

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

Sidebar

Related Questions

I'm trying to create an xsd schema that will validate a map with an
I have two textboxes, with that am trying to validate like var max =
I'm trying to develop a schema that will validate some existing XML files I've
I'm trying to validate user input data using jquery. Here is the code I
The webserver i'm using is Apache 2.2. I'm trying to validate a domain that
When trying to validate my site, I get the following error: Line 188, column
While trying to validate my forms i get the following error: Expected a {
While trying to validate form data on my page i get the following error:
I am trying to validate two checkboxes. One of them must be checked in
i am trying to validate a user registration form in Zend Framework 2. More

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.