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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:32:29+00:00 2026-06-11T03:32:29+00:00

Update: The Question is Still Open, any reviews, comments are always welcome I am

  • 0

Update: The Question is Still Open, any reviews, comments are always welcome

I am having an existing rails project in which some important files and directories has been missed.

project rails version (2.3.8) i found it in environment.rb

currently what i am having is

app
   controllers (already fully coded)
   helpers  (already fully coded)
   models (already fully coded) 
   reports (already fully coded)
   views  (already fully coded)

config ---> default configurations (already fully coded)
lib ---> contains nothing
public --> contains images and scripts (already fully coded)
script ---> contains server,runner,plugin,dbconsole....

app directory fully contains working state of codes, app/model contains more than 100 .rb files , so i assume it will be more than 100 tables

the mainly missing things are db directory, .gem file, rake file, doc, test, vendor, database,schema.rb and migrations

Note:
i don’t have the table schema and database for that project

i am in Need to generate tables or complete database from models and views and
i am looking for reverse engineering kind of stuff for generating db schema from models or views

I am newbie to rails and i am from java background , in java by using hibernate there is an pojo(model in rails) to database option available, i am looking for similar kind of stuffs for rails , and my main aim to run that project , so guys please help me.

  • 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-11T03:32:31+00:00Added an answer on June 11, 2026 at 3:32 am

    To recreate the database schema, it will take quite a bit of time.

    You can get a lot of information about the database in the app/models, app/controllers app/views directory.

    You should know that ActiveRecord does not require you to explicitly list all the attributes of a model. This has important implications – you can only infer what attributes you still have to add to the database, based on whether an attribute is referred to! This means doing this will be a bit of an ART. And there are no CLEAR steps to complete this work. But below are some rules which you can use to HELP you.

    This is a BIG project, below are guidelines, rules and tips to help you. But be aware that this could take a long time, and be frustrating at times to get this done.


    What Tables you need:

    Each table will normally have a matching ActiveRecord::Base model. So in the app/models directory, check each file, and if the class inherits from ActiveRecord::Base, it is an extra table.

    The table name is by default a pluralized snake case version of the name of the class.

    class UserGroup < ActiveRecord::Base # for this class
    

    the name of the table is user_groups. Notice it is plural, and instead of camel case, it is lowercase, with underscores to separate the words.

    All these tables will have an “id” integer column. By default, the tables also have a “created_at”, and “updated_at” column of type datetime.

    Associations and foreign keys:

    You can infer what foreign keys exist by the associations in the Models. All associations are explicitly listed, so this is not too hard.

    For example:

    class UserGroup < ActiveRecord::Base # for this class
      belongs_to :category
    

    This means that the user_groups table has a column named “category_id”, which is a foreign key for the categories table.

    This means that the Category model likely has an inverse relationship (but no extra column):

    class Category < ActiveRecord::Base
      has_many :user_groups
    

    The main other association is the has_many_and_belongs_to association. Eg.

    class A < ActiveRecord::Base
      has_and_belongs_to_many :bs
    end
    class B < ActiveRecord::Base
      has_and_belongs_to_many :as
    end
    

    This means that there is a join table to add called “as_bs” (as and bs are sorted alphabetically), with the foreign keys “a_id” and “b_id”.

    All foreign keys are integers.


    Attributes

    Ok, so that’s the table associations. Now for the normal attributes…

    You should check the app/views/user_groups/ or other similar app/views directories.

    Inside you will find the view templates. You should look at the _form.html.erb templates (assuming it is .erb templates, otherwise it could be .haml etc templates).

    The _form.html.erb template, if it exists, will normally have many of the attributes listed as form fields.

    In the form_for block, check if it says something like f.text_field :name, it means there is an attribute/(column in the table) called “name”. You can infer what type the column should be by what type of field it is. Eg. in this case, it is a string, so maybe a VARCHAR(255) is appropriate (referred to as string in Rails).

    You might also need to infer what type is appropriate based on the name of the attribute (eg. if it mentions something like :time, then it is probably either of type Time or DateTime).

    This may give you all the other attributes in the table. But in some cases, you might miss the attributes. If you find a reference to other attributes in the controller, eg. app/controllers/user_groups_controller.rb, then you should add that as a column in your table. You can leave this until the end when you test it though, because when you test it, if an attribute is missing, then it will throw a NoMethodError for the object of the relevant model. Eg. if it says that @user_group variable, of class UserGroup, is missing a method named title, then it probably is missing a column named “title” of type string.


    Recreate your migration/database

    Ok, so now you know what the database tables and column names and types should be.

    You should generate/recreate a migration for your database.

    To do this, just use the command rails generate migration RecreateTables.

    Then you should find a file in db/migrate/???_recreate_tables.rb.

    Inside, start writing ruby code to create your tables. Reference for this can be found at http://guides.rubyonrails.org/migrations.html.

    But essentially, you will have something like:

    class RecreateTables < ActiveRecord::Migration
      def up
        create_table :user_groups do |t|
          t.string :name # adds a string (VARCHAR) column called "name"
          t.text :description # adds a textarea type column called "description
          t.timestamps # adds both "created_at" and "updated_at" columns for you
        end
      end
    
      def down
        drop_table :products # this is the reverse commands to undo stuff in "up"
      end
    end
    

    To recreate your Gemfile:

    Start by adding a default Gemfile. This can be done by using rails new testapplication somewhere to create an empty rails application. Then copy the Gemfile to your actual application. It will get you started by including rails and other common gems.

    It is VERY hard to work out exactly what gems are needed. The best you can do is try adding them one by one as you look through the code.

    Again, here, MethodNotFound errors are your FRIEND. When you test the application, based on the gems you have added, it might detect some missing methods which might be supplied by gems. Some missing methods on models might indicate missing gems (or they might indicate missing fields/columns in the database). However, missing methods on Controller or ActiveRelation classes are VERY likely because of missing gems.

    You will have to look through the code and try to infer what gems to add.

    If it uses methods like can, can?, and has a file app/models/ability.rb, then you need gem 'cancan'. If it calls devise in a model, it needs gem 'devise'. Many common gems can be seen at http://ruby-toolbox.com.

    After adding gems to your Gemfile, you should run bundle on your command line to install the new gems before testing again. When you test it again, you should restart your test server. Rerun bundle exec rails server to start a local test server on localhost:3000 or something like that.

    You can simply copy the Rakefile from rails new testapp, and it will probably include everything you need.

    Missing Tests

    The missing test/ directory is not relevant to your actual application. It is not required to run the application. However, it does hold automatic scripts to test your application. You will have to re-write new tests if you want to automatically test your application. However for the purpose of getting your application back up, you can ignore it for now.

    Missing vendor directory

    Some extra code is not installed as a gem, but as a plugin. Anything installed as a plugin is lost if you don’t have the vendor directory. As with gems, the best you can do is try to infer what might be missing, and re-download the missing plugin, either re-installing the plugin, or using a gem replacement.


    Additional tips:

    • Try reading some of the comments which might name some of the gems used.

    • If a method or set of methods are missing, that you think are not database fields/columns, it might be due to a missing gem. The best thing to do is to search google for those method names. Eg. if it is missing “paginate”, you can search “rails paginate gem”, and see what likely gems you might need. This example will probably come up with “will_paginate”, and “kaminari”. Then you have to try and infer which of the gems are required. Maybe do a grep will_paginate app -r on the command line to see if it is using will paginate. The grep command searches for the string “will_paginate”, in the directory called “app”, -r makes it do this recursively for all files

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

Sidebar

Related Questions

Update: The Question is Still Open, any reviews, comments are always welcome As I
UPDATE I answered my question below, but I am still asking for a prettier
Update: This question is a duplicate of Are there any programming languages targeting PHP,
UPDATE : Since this question is getting some views, I figured I'd better highlight
********Update to Question********** If the tableview does not affect the model: Are the index
UPDATE: This question is out of date, but left for informational purposes. Original Question
Update: This question was an epic failure, but here's the working solution. It's based
Sorry for the double post, I will update this question if I can't get
UPDATE (spoiler): This question is answered (see David Carlisle answere below) and it looks
Update : I found almost exact similar question , yet it has slightly different

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.