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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:19:21+00:00 2026-05-10T18:19:21+00:00

We are making a Ruby On Rails webapp where every customer gets their own

  • 0

We are making a Ruby On Rails webapp where every customer gets their own database.
The database needs to be created after they fill out a form on our website.

We have a template database that has all of the tables and columns that we need to copy. How can I do this in programatically from ruby on rails?

  • 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. 2026-05-10T18:19:21+00:00Added an answer on May 10, 2026 at 6:19 pm

    From any controller, you can define the following method.

     def copy_template_database         template_name = 'customerdb1' # Database to copy from         new_name = 'temp' #database to create & copy to          #connect to template database to copy.  Note that this will override any previous         #connections for all Models that inherit from ActiveRecord::Base         ActiveRecord::Base.establish_connection({:adapter => 'mysql', :database => template_name, :host => 'olddev',         :username => 'root', :password => 'password' })          sql_connection = ActiveRecord::Base.connection          sql_connection.execute('CREATE DATABASE #{new_name} CHARACTER SET latin1 COLLATE latin1_general_ci')         tables = sql_connection.select_all('Show Tables')         #the results are an array of hashes, ie:         # [{'table_from_customerdb1' => 'customers'},{'table_from_customerdb1' => 'employees},...]         table_names = Array.new         tables.each { |hash| hash.each_value { |name| table_names << name }}          table_names.each { |name|              sql_connection.execute('CREATE TABLE #{new_name}.#{name} LIKE #{template_name}.#{name}')             sql_connection.execute('INSERT INTO #{new_name}.#{name} SELECT * FROM #{template_name}.#{name}')         }         #This statement is optional.  It connects ActiveRecord to the new database         ActiveRecord::Base.establish_connection({:adapter => 'mysql', :database => new_name, :host => 'olddev',         :username => 'root', :password => 'password' })     end 

    Note that I do not know for sure if this will keep foriegn key integrity. I think it depends a lot on how the template Database is created.

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

Sidebar

Ask A Question

Stats

  • Questions 100k
  • Answers 100k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The only resource that I know off is the code… May 11, 2026 at 7:56 pm
  • Editorial Team
    Editorial Team added an answer By Timestamp, I presume you mean java.sql.Timestamp. You will notice… May 11, 2026 at 7:56 pm
  • Editorial Team
    Editorial Team added an answer Well, I finally found a hint in the atozed-Forums: Copying… May 11, 2026 at 7:56 pm

Related Questions

We are making a lab instrument using an ARM9/RTOS system. The client has asked
I and two others are working on a project at the university. In the
We have an issue using the PEAR libraries on Windows from PHP . Pear
We had a meeting this morning about how would should store our ID for

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.