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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:43:26+00:00 2026-05-17T19:43:26+00:00

I am using rails to build a web app which provides each business with

  • 0

I am using rails to build a web app which provides each business with its own account and subdomain, Similar to how basecamp (and other 37 signals apps) lighthouseapp.com, and so on.

Now I know that there are lots of decent tutorials on how to do subdomains in rails, and even the subdomain-fu plugin.

The thing is that I want to use the users email address as their login, which means it needs to be unique, however I only want it to be unique to each account rather than across all accounts.

I am using devise for authentication, and I have created an “Accounts” model which represents the account, and a user model to represent the users for that account. Devise operates on the user model, and it would appear that it would require each user to have a unique email address.

Have I stated the issue clearly enough? I can gladly provide clarification.

Can anyone point me in the right direction?


Clarifying some details for Tim

  • Q: How many accounts can an individual
    business have?
  • A: Each individual business would have one account. Such as “Springfield Maths grinds”

  • Q: Is there a one-to-one correlation between subdomains and accounts?

  • A: Yes, such as springfield-maths-grinds.myapp.com

  • Q: Does a “user” correspond to a physical person, or a role within an account?

  • A: I should have explained this better. I actually have two separate models, e.g. tutor and student. Each account would have multiple tutors and students.

businesses, accounts, subdomains
businesses & accounts are effectively the same thing. A ‘business account’ so to speak.
I am using subdomains to access each ‘business account’

logins, users, email addresses
I should clarify that I have two types of user which are represented by separate models, these are tutor and student. These will need to login to the app and I want to use an email address as their login, instead of a username.

Hopefully that clears things up rather than making it worse.

My actual problem is as follows,
If someone were to setup a business account for “Springfield physics grinds” and one of the students of “Springfield maths grinds” tried to sign-up, then they would be unable to do so because the email address is already in use and needs to be unique. I want to know how to scope the students and tutors within a business account.

  • 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-17T19:43:27+00:00Added an answer on May 17, 2026 at 7:43 pm

    There’s two things you need to think about. Data integrity and authentication.

    Rails lets you scope uniqueness to one or more columns. With scoping you could have multiple foo@bar.local e-mail addresses in the database with the constraint of only one per account. I’ve included what the corresponding SQL might look this to demonstrate how this works.

    # Without scoping
    validates :email, :uniqueness => true
    SELECT 1 FROM `users` WHERE `users`.email = 'foo@bar.local'
    
    # With scoping
    validates :email, :uniqueness => true, :scope => :account_id
    SELECT 1 FROM `users` WHERE `users`.account_id = 1 AND `users`.email = 'foo@bar.local'
    

    I’m assuming you’re using Rails 3. You can pass the same option to validates_uniqueness_of if you’re using Rails 2.

    For authentication, you’ll want to find the account, ensure the user belongs to that account and check that their password matches. When you present the login form to the user, you’ll already know which account their authenticating against. Your action might look like this.

    def create
      @account = Account.find_by_subdomain(params[:subdomain])
      @user    = @account.users.find_by_email(params[:user][:email])
      if @user.authenticate(params[:user][:password])
        redirect_to dashboard_path
      else
        render :new
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.