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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:47:06+00:00 2026-06-11T17:47:06+00:00

I am using the acts_as_tenant gem to manage multi-tenancy, and I’m using devise to

  • 0

I am using the acts_as_tenant gem to manage multi-tenancy, and I’m using devise to manage users.

I have only setup devise User model and Account model for tenants.
I can create users against multiple tenants – this is all working fine EXCEPT when I attempt to create two users with the same email against different tenant ID’s I get a uniqeness error.
I am using the validates_uniqueness_to_tenant option as described.

User model

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  attr_accessible :email, :password, :password_confirmation, :remember_me

  acts_as_tenant(:account)
  validates_uniqueness_to_tenant :email
end

Account model

class Account < ActiveRecord::Base
  attr_accessible :name
end

Application Controller

class ApplicationController < ActionController::Base
  set_current_tenant_by_subdomain(:account, :subdomain)
  protect_from_forgery
end

This looks like it should be working based on all documentation in acts_as_tenant, do I need to override something at the devise level instead?

EDIT: After some head-scratching and a bit of a break, the problem is I believe because by default Devise has added a unique index to the Email column.
This obviously does not gel with what acts_as_tenant wants to do…
I will try removing the index and see whether Devise pukes or not.

EDIT 2: OK, have officially given up on this for now. I have hand-rolled authentication for the main site and this is working properly with acts_as_tenant.
I can only assume some incompatibility between acts_as_tenant and Devise at some layer – beyond me to find it at this stage.

  • 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-11T17:47:07+00:00Added an answer on June 11, 2026 at 5:47 pm

    The only way to do this is by removing the validatable module from devise and run your own validations like so:

    class User < ActiveRecord::Base
      acts_as_tenant :account
      attr_accessible :email, :password, :remember_me
    
      #remove :validatable
      devise :database_authenticatable, :registerable,
        :recoverable, :rememberable, :trackable
    
      #run own validations
      #I've omitted any emailformatting checks for clarity's sake.
      validates :email, 
        presence: true,
        uniqueness: { scope: :account_id, case_sensitive: false }
      validates :password,
        presence: true,
        length: { :in => 6..20 },
        :if => :password_required?
    
    protected
      # copied from validatable module
      def password_required?
        !persisted? || !password.nil? || !password_confirmation.nil?
      end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am working on rails 3 and using acts_as_taggable_on gem I have blog,Article associated
I'm using acts_as_taggable_on and tags are associated to a Brand model. Users, via a
i have a problem using acts_as_textiled and has_foreign_language plugins together. TextElement my model in
Using: Rails 3.1.1 I have a controller/model/view called Category that is built up on
I'm using acts-as-messageable , a rails gem, in an app i have. However in
I'm using acts_as_taggable_on, but now have a new requirement: The end goal: Users should
Using Rails 3.1.1 and the gem acts_as_tree. I have googled the issue and checked
I'm using acts_as_audited gem in Ruby it works fine. When I created, updated or
I'm using acts_as_taggable_on in a model, and am trying to implement the auto_complete plugin.
I'm using acts_as_taggable_on and I'm trying to query for all users tagged with any

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.