Running a Rails App

In this demo, I will show how to download, configure, and run an existing Rails web app hosted on GitHub (Rails 6 Test App). This demo will also serve as a good test of whether our development environment was set up correctly.

1. Downloading the Project

First, we will create a workspace for our Rails projects and download the test app.

  1. Using your terminal application, create a folder workspace in your home directory by entering this command:

     mkdir ~/workspace
    

    This folder is where all our Rails projects will go.

  2. Change directory to your workspace folder by entering this command:

     cd ~/workspace
    
  3. Use Git to download the test-app project by entering this command:

     git clone https://github.com/human-se/rails-6-test-app-2020.git
    
  4. Verify that the download was successful by entering the following command:

     ls -l
    

    You should see that a new rails-6-test-app-2020 directory has been added to the workspace directory.

2. Installing Project Dependencies

Next, we will install the Ruby and JS package dependencies for the project.

  1. Change the working directory to the rails-6-test-app-2020 directory by entering this command:

     cd rails-6-test-app-2020
    

    When you run this command, RVM should print a message like the following, which lets you know it’s working. Note that this message appears only after the first time you cd into a new project.

     ruby-2.6.5 - #gemset created /home/vagrant/.rvm/gems/ruby-2.6.5@quiz-maker
     ruby-2.6.5 - #generating quiz-maker wrappers.........
    

    If no messages from RVM appears, then something is wrong. A common problem is that the terminal application is not configured to run as a "login" shell. This issue seems to come up the most for Linux users, or users of more exotic terminal applications. Typically, the solution can be found in the terminal application's settings. Restarting the terminal application after fixing the setting will likely be necessary.

  2. Download and install the gems (Ruby libraries) for this Rails project by entering the following command:

     bundle install
    
  3. Download and install all the JS packages for this Rails project by entering the following command:

     yarn install
    

3. Setting Up the Database Backend

Next, we will initialize the database for the project.

  1. Wipe and reset the database to be used by this Rails app by entering the following command:

     rails db:migrate:reset db:seed
    

4. Running the Project

We should now be able to run the project. We will first run the project’s automated tests. If the tests are working correctly, we will then launch the web server and open the web app in a browser.

  1. The project comes with some automated tests. Run them by entering the following command:

     rails test
    

    You should see that all the tests passed.

  2. Start up the Rails web app server by entering the following command:

     rails s
    

    You should see that the server has started without error. Note that this command will not “return” like other commands—that is, the command prompt will not reappear until you halt the server process (covered below).

    Note that the s in the above command is short for server, and the command can alternatively be entered as follows:

     rails server
    
  3. Open the URL http://localhost:3000 in a web browser. You should see a “QuizMaker” web app with a list of quizzes.

  4. Further test out the web app by logging in and creating a quiz:

    1. Follow the Sign In link at the top right and log in with the email alice@email.com and the password password.

    2. Click the Create New Quiz link and enter a title and description for a quiz.

    3. Add questions to the quiz by clicking to Edit Quiz link.

5. Inspecting the Database with pgAdmin

Verify that the Postgres DBMS running on the server is accessible and that the app’s database is configured as expected.

  1. Launch pgAdmin 4, entering your pgAdmin password when prompted.

  2. Add a new Server by first making the following selection:

    Object > Create > Server...

  3. Next, set the following configuration fields for the new server:

    Field Value Explanation
    Name SoftwareEng Just a made-up name for this Postgres database.
    Hostname/address localhost Tells pgAdmin that the database service is running on this machine.
    Port 5432 The port on which the Postgres service listens.
    User homer Your Unix username on the system. Replace homer with your actual username.
    Password password1 The Postgres password for your username. Replace password1 with the password you entered when configuring Postgres in the previous demo.

    Once you’ve entered these data, click Save.

  4. Inspect the demo web app’s databases by performing the following steps. In the left sidebar, navigate as follows:

    Servers > SoftwareEng > Databases > default_development > Schemas > public > Tables

    Right click on quizzes and go to View/Edit Data > All Rows.

    You should see the Data Output panel in the bottom right corner of the screen showing information about all the quizzes in the application.

As we begin developing the demo app, using pgAdmin in this way can be very useful for verifying that our app databases are being configured properly and for debugging problems.