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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:55:59+00:00 2026-05-16T20:55:59+00:00

Rails 3 newbie here…. I’m looking to build an application that limits a user’s

  • 0

Rails 3 newbie here…. I’m looking to build an application that limits a user’s viewable data to their company, which is based on their email’s domain. Very much like Yammer or basecamp. I’m currently using devise for auth…

I’d like a User’s table and then a UserInstance Table… The UserInstance table would look like:

ID | domain 
 1 | yahoo.com 
 2 | github.com 
 3 | abc.com

I’d like for the each record in the user table to have an InstanceID that has an ID from the UserInstance table. During registration the UserInstance is either found or assigned (unique)…. Then, all records in the DB would have an InstanceID. Now that all users are assigned to an instanceID… I’d like everything the signed in user sees in the site to only be for their InstanceID, so company’s information is silo’d.

Question:
1. How to modify devise to support the UserInstance table, to assigned or create and then assigned instanceID on registration

So far I’m here, /app/models/user.rb

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
  attr_accessible :email, :password, :password_confirmation, :remember_me

    after_create :assign_user_to_instance

    def assign_user_to_instance
        logger.debug "Called after the account was created"
    end

end

What I’d like to see happen in assign_user_to_instance is as follows:

def assign_user_to_instance
 Step 1, extract the user's domain from the email address they just registered with
 Step 2, does this domain from s1 exist in the UserInstance Table (domain)?
 Step 2b, if not create it and grab the UserInstance.ID
 Step 2c, if it does, grab the already available UserInstanceID
 Step 3, assign the UserInstanceID to the user's record in the user table
end

Any help implementing the pseudo code above would be greatly appreciated.

Thanks!

  • 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-16T20:56:00+00:00Added an answer on May 16, 2026 at 8:56 pm

    User model:

    class User < ActiveRecord::Base
      # devise stuff
      belongs_to :instance, :class => 'UserInstance'
      def assign_user_to_instance
        domain = email.split("@").last
        user_instance = UserInstance.find_or_create_by_domain domain
        update_attribute(:instance_id, user_instance.id) #or whatever you called this field
      end
    end
    

    and you need a migration like this:

    > rails g migration AddUserInstanceToUser
    

    The migration should look like this:

    class AddUserInstanceToUser < ActiveRecord::Migration
      self.up
        add_column :users, :instance_id, :integer
      end
      self.down
        remove_column :users, :instance_id
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Rails newbie here. I have a legacy sqlite3 database that I have no control
Rails newbie here. I'm looking to learn a little bit about jQuery so I
Rails 3 newbie here... I'm working to create a devise auth system that like
Rails newbie here struggling with a small project. I am creating a simple ship
this newbie here is smacking his head with webservices over Rails. Perhaps someone could
First off I'm a total Rails newbie (front-end guy looking to learn rails), so
I am newbie to Rails and trying to write application with TDD and BDD.
I am a newbie to Rails and I have seen that to write HTML
I am a newbie in Rails and am working on a page that enables
Rails newbie here so just want to be sure I'm doing this right. I

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.