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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:54:07+00:00 2026-06-12T22:54:07+00:00

I was adding uniqueness validation to the model in charge of user registration. The

  • 0

I was adding uniqueness validation to the model in charge of user registration. The username should be uniqueness.
I created a user when testing some days ago, lets call it “example-guy”. Then I deleted him from the scaffolding user interface and now when trying to register a new user as “example-guy”, it returns that the name has already been taken.
So how can I fix this from the DB without reverting to its “birth-state” and modify the controller to actually destroy the table entry?

Or maybe Rails is keeping track of what was writed to DB, even after destruction?

Im using omniauth-identity, the user model:

class User < ActiveRecord::Base
  attr_accessible :name, :provider, :uid, :email
  # This is a class method, callable from SessionsController
  # hence the "User."
  def User.create_with_omniauth(auth)
    user = User.new()
    user.provider = auth["provider"]
    user.uid = auth["uid"]
    user.name = auth["info"]["name"]
    # ADD EMAIL
    user.email = auth["info"]["email"]
    user.save
    return user
  end
end

User controller’s destroy function:

  # DELETE /users/1
  # DELETE /users/1.json
  def destroy
    @user = User.find(params[:id])
    @user.destroy

    respond_to do |format|
      format.html { redirect_to users_url }
      format.json { head :no_content }
    end
  end
end

Validations are made trought “Identity” model inherited from omniauth’s active record:

class Identity < OmniAuth::Identity::Models::ActiveRecord
  attr_accessible :email, :name, :password_digest, :password, :password_confirmation
  #attr_accessible :email, :name, :password_digest :password, :password confirmation
  validates_presence_of :name
  validates_uniqueness_of :name
  validates_length_of :name, :in => 6..24
  validates_format_of :name, :with => /^[a-z]+$/
  validate :name_blacklist

  validates_uniqueness_of :email, :case_sensitive => false
  validates_format_of :email,
  :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i,
  :message => "doesn't look like a proper email address"
  #validates_presence_of :password, on: :create
  #validates_presence_of :password_confirmation
  validates_length_of :password, :in => 6..24

  def name_blacklist
    unless self.name.blank? then
      case self.name
      when "user", "photo", "photos",
        "application", "sessions",
        "identities", "home"
          self.errors.add(:name, "prohibited")
      end
    end
  end
end

Identities controllar manage registration form sent to omniauth and calling new.html.erb:

class IdentitiesController < ApplicationController
  def new
    @identity = env['omniauth.identity']
  end
end

Thanks in advance.

  • 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-12T22:54:08+00:00Added an answer on June 12, 2026 at 10:54 pm

    I’m not entirely sure what caused the problem, but I came across a similar problem but with email addresses with a Devise based user.

    I was wanting to re-use the same email on a different user. I changed the original user to a different email, but when I then tried to update the second user with the “now unique” email, it failed the unique validation.

    A query for users with that email returned nothing.

    It seemed to be cache-related to the uniqueness constraint, as restarting the server, after deleting the email address, fixed the problem.

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

Sidebar

Related Questions

I just did a push to Heroku and tried doing some testing by adding
I have a rails model that I am adding validations to and I seem
Adding some gui modifications and I want to have a button which is 10pixels
Adding files to .hgignore will prevent them from being tracked. But we have some
Adding this code def send_messages return if recipient_list.blank? recipient_list.each do |recipient| recipient = User.find(recipient)
Adding a list item via the SharePoint web service model, any idea how to
My User model has an attribute called points and when I try to update
Adding a new column or adding a new index can take hours and days
Adding more and more configurations to my servlet container ( Embedded Jetty in my
Adding more than one child to a WPF StatusBar results in poor layout with

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.