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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:54:30+00:00 2026-05-12T17:54:30+00:00

I am about to begin writing a Rails application that will allow clients to

  • 0

I am about to begin writing a Rails application that will allow clients to have a separate subdomain for their access to our application. Thinking from a data security standpoint, it would be nice if each client’s access was truly limited to their database, that way, if there is a bug in production code, they would only be able to access their own database and not that of any other clients.

I know the code behind how to do what I want, but I was wondering if there was a simpler solution that I might be missing. How would you go about securing client data so that in the event of a bug or hacker threat, their data would be less likely to be exposed?

  • 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-12T17:54:31+00:00Added an answer on May 12, 2026 at 5:54 pm

    Here is some code I use for this very problem:

    application_controller.rb

    before_filter :set_database
    
    helper_method :current_website
    
    # I use the entire domain, just change to find_by_subdomain and pass only the subdomain
    def current_website    
      @website ||= Website.find_by_domain(request.host)
    end
    
    def set_database
      current_website.use_database
    end
    
    # Bonus - add view_path
    def set_paths
      self.prepend_view_path current_website.view_path unless current_website.view_path.blank?
    end
    

    Website.rb

    def use_database
      ActiveRecord::Base.establish_connection(website_connection)
    end
    
    # Revert back to the shared database
    def revert_database
      ActiveRecord::Base.establish_connection(default_connection)
    end
    
    private
    
    # Regular database.yml configuration hash
    def default_connection
      @default_config ||= ActiveRecord::Base.connection.instance_variable_get("@config").dup
    end
    
    # Return regular connection hash but with database name changed
    # The database name is a attribute (column in the database)
    def website_connection
      default_connection.dup.update(:database => database_name)
    end
    

    Hope this helps!

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

Sidebar

Related Questions

I'd like to begin thinking about how I can scale up my algorithms that
I am about to begin building a small application for a user to manage
I'm writing an application that uses renaming rules to rename a list of files
I am writing a simple app where I have a UIImageView that when clicked
I apologize if I seem unknowledgable. I have only been writing T-SQL for about
I'm about to begin working on a collaborative effort with another vendor. The vendor
I'm about to begin work on translating client's website into spanish and french and
I'm relatively new to J2ME and about to begin my first serious project. My
My question concerns Google Web Toolkit (GWT). I'm about to begin development for a
After some stupid musings about Klingon languages, that came from this post I began

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.