PA Rails 1

Intro

This assignment introduces the MVC architecture of Rails as you design a Web app in which users can select university classes. The data you need is available at This Google Drive folder. The folder has 3 JSON files, each is a JSON array. Note: If you are using or already loaded data from the original URL, then you’ll need to iterate through each line of that file and parsing each line as JSON - The entire file is not JSON formatted, just individual lines. Also DO NOT use/load entries of type “section” - there are too many of these and you’ll end up exceeding the 10K records for a free database on Heroku. Only use data of type instructor, course and subject.

The purpose of this assignment is for each student to independently practice their knowledge of the material separate from the team work. What you learn and practice here will definitely contribute to your work on the team project. You will be using a lot of what you are learning in class and in the RORT. You might have to read ahead a little.

In the first part (of 3) you will build a basic rails application that imports and displays the data according to the instructions below.

Part 1: Bootstrap UI, Import JSON files and Display data

  1. Before creating your application: Since we will be deploying our app to Heroku, you MUST use PostgrSQL instead of sqlite because Heroku does not support sqlite. Follow this comprehensive tutorial After following this tutorial you will have an app that’s up and running! Be sure to fully understand RORT chapters 1 & 2 before you follow this abridged tutorial.
  2. As chapter 2 suggests, I highly recommend you setup a (private) GitHub repo and automatic deployment to Heroku at this step. It is far simpler to deploy to Heroku now than later on in the assignment. This step is covered in the short tutorial above, but you must generate multiple scaffolds.
  3. Use rails generate scaffold to generate appropriate models and views in order to represent the data for instructor, subject, and course.
  4. Once you have created the above scaffolds, play with it to get a feel for what you have.
  5. The university data is formatted in JSON. just examine the data. I have provided three separate JSON files. You will find detailed description from the university specifying the data schema. You can find it here:Google Drive folder. Take your time to understand each file and the data it contains/how it is organized. You need to look at the JSON files to see what the fields are that will be available. For example, courses have a field for the subject, which is a number. The number corresponds to a record in the subject database. For now, it’s ok if you just display the course number.
  6. You will need the JSON gem to read the files in. Inspect the files to see what the fields are you will need for your database tables. Instructions to read JSON files can be found here: https://hackhands.com/ruby-read-json-file-hash/
  7. Load the data into your database tables. You don’t need to store every field/attribute, just the ones you would need and like to include in your app. The logical place for that code is in the db/seeds.rb file. There are several ways to code the import. Here’s a good article about Importing Large Datasets in Ruby on Rails. Note that the instructions in the article are not meant to be copied verbatim! However, they are very similar to what you will need to do. Carefully examine the code in the instructions and modify it to fit our app. You will need to do some more digging around tthe web to get this done, but this is a very clear and ambiguous task. 5. If you followed the RORT chapters, by this point you should have a home page. The home page of the application should display three tabs, as follows:
  8. The home page of the application should display three tabs, as follows.
    • Subjects - Displays all the subjects from the database
    • Courses - Displays all the courses from the database
    • Instructors - Displays all the instructors from the database
    • (If you are having trouble with setting up a home page with multiple tabs then re-read and re-do chapters 1-4)
  9. The final step of this assignment is to set up your application to use Bootstrap for the UI. This can be easily accomplished if you follow RORT chapter 5. Only do this step once you have finished all the other steps.

Deliverables:

  1. Write a readme.md for your app including link to a private GitHub repo and your link to Heroku.
  2. Submit to Latte a zipped up folder of your app.

Timesaving Tips

  • Check out these really useful gems
    • json to parse and process json files
    • activerecord-import to make loading lots of records faster and more efficient
    • better-errors to give you more legible errors from Rails
    • pry-rails to invoke the nicer repl called pry when you do a rails console
1# Gemfile
2group :development do
3  gem 'json'
4  gem 'activerecord-import'
5  gem "better_errors"
6  gem "pry-rails"
7end

#### Useful Links * ActiveRecord Import * Importing Large Datasets in Ruby on Rails

Continue to next pa in this sequence

Click here to continue to PA Rails 2