DEV Community

DavidNNussbaum
DavidNNussbaum

Posted on

A Quick Guide To Setting Up a Rails Directory

First create a new repo on github.

In your terminal, cd to the directory in which you want the rails directory to reside. Please note the words directory, file-name, YourName, ModelName, and column_name are being used as generic terms to be replaced with the actual names that you are using.

Now enter:
*~/directory$ rails new file-name -T --database=postgresql --no-test-framework *
Please note that if you do not enter -T --database=postgresql, to install PostgreSQL then the default database is SQLite.

If you do not enter --no-test-framework then the default is to include the extra test files.

Next cd to the created rails file:

~/directory$ cd file-name

The next steps will allow you to push your changes to github. Enter the following with everything after the word origin being a copy of the SSH from your github repo.

~/directory/file-name$ git remote add origin git@github.com:YourName/file-name.git

Next enter:

~/directory/file-name$ git branch

Followed by:
~/directory/file-name$ git status
The following will appear in the terminal:
On branch master

No commits yet

Next add (the period after a space is part of the entry):

~/directory/file-name$ git add .

Followed by:

~/directory/file-name$ git commit -m "Setting up the file."

Then enter:
~/directory/file-name$ git status
The following will appear in the terminal:
On branch master

nothing to commit, working tree clean

Next enter:

~/directory/file-name$ git branch -M master

Followed by:

~/directory/file-name$ git push -u origin master

Next enter:

~/directory/file-name$ git pull origin master --allow-unrelated-histories

Followed by:

~/directory/file-name$ git push --set-upstream origin master

If you are installing PostgreSQL enter, otherwise skip this step:

*~/directory/file-name$ gem install pg *

No matter what your database is the next step is:

~/directory/file-name$ bundle install

Followed by:

~/directory/file-name$ rails db:create

To set up each model enter:
~/directory/file-name$ rails g model ModelName column_name:type foreign_key:references
Please note that you can add in as many columns as are present for this model. The references term will create a column called whatever the foreign key is with _id attached.

Thanks for reading!

Top comments (0)