FlatironStudents: Ruby on Rails Project

Charles Angelo Lai
4 min readFeb 8, 2021

In the third phase of my journey in Flatiron’s Software Engineering Bootcamp, we were tasked to build a complete Ruby on Rails Content Management System (CMS) application. This was by far one of the toughest projects I have tackled in my journey to becoming a Software Engineer, and I am so grateful to have learned so much through it.

Project Requirements

  1. Use the Ruby on Rails framework
  2. Your models must include at least one has_many, at least one belongs_to, and at least two has_many :through relationships.
  3. Your models must include reasonable validations for the simple attributes. You don’t need every possible validation or duplicates, such as presence and a minimum length, but the model should defend against invalid data.
  4. You must include at least one class level ActiveRecord scope method. Your scope method must be chainable, meaning that you must use ActiveRecord Query methods within it (such as .where and .order) rather than native ruby methods (such as #find_all or #sort).
  5. Your application must provide standard user authentication, including signup, login, logout, and passwords.
  6. Your authentication system must also allow login from some other service. Facebook, Twitter, Foursquare, GitHub, etc…
  7. You must include and make use of a nested resource with the appropriate RESTful URLs which should include routes to a nested new, index, and show.
  8. Your forms should correctly display validation errors.
  9. Your application must be, within reason, a DRY (Do-Not-Repeat-Yourself) rails app.
  10. Do not use scaffolding to build your project.

Project Overview

FlatironStudents is a Ruby on Rails CMS web application built with the objective of connecting Flatiron students across multiple cohorts and multiple programs. The application allows students to share the projects they have built throughout the five phases of Flatiron Schools Bootcamp, submit and receive surveys regarding the projects they have built which will be visualized for each student in their projects page, the survey submissions will of course be anonymized. It also features an activity dashboard that tracks Create, Update and Delete actions within the users and projects databases. (I will be expanding this to track the cohorts table as well as the forum section soon). The application also features a forum section were students will be able to create and have discussions, and last but not least, an admin user and dashboard (one user to rule them all).

Models, Associations, and Database Schema:

We will be using ten models for this project and the associations between each of them are as follows:

User

  • belongs_to :cohort
  • belongs_to :role
  • has_many :projects
  • has_many :survey_responses, through: :projects
  • has_many :posts
  • has_many :comments, through: :posts

Cohort

  • has_many :users

Role

  • has_many :users

Project

  • belongs_to :user
  • has_many :survey_responses

Survey

  • has_many :survey_questions
  • has_many :survey_responses

SurveyQuestions

  • belongs_to :survey

SurveyResponse

  • belongs_to :survey
  • belongs_to :project

Category

  • has_many :posts

Post

  • belongs_to :category
  • belongs_to :user
  • has_many :comments

Comment

  • belongs_to :post
  • belongs_to :user

Database Schema

FlatironStudents schema.rb

User Authentication

For this part of the project, we will be utilizing Devise, a flexible authentication solution for Rails based applications.

  1. Add the following into your Gemfile and run bundle install.
> Gemfile
gem 'devise'
> Console
$ bundle install

2. Run the devise generator below to generate our devise local and initializer files.

$ rails g devise:install

3. Let’s run the devise generator again and pass in a model name of User. This should generate our devise model and migration files for our User model, as well as update our routes.rb file to include :users.

$ rails g devise User

4. Next, let’s generate our devise controllers to the scope of users with the following command.

$ rails g devise:controllers users

5. Once everything runs successfully, let’s run the command below to migrate our database into our rails application.

$ rails db:migrate

Omniauth with GitHub

In order to add Omniauth with GitHub, we must first sign-in to GitHub and navigate to the developers console and register our new application.

  1. Click on “New OAuth App” to register our application.
  2. Fill-up the form your applications information. For now let’s use our rails server as our URLs.

3. Click on “Generate a new client secret” and copy the values of both the client id and client secret.

4. Add the following gems into our Gemfile and run bundle install.

> Gemfile
gem 'omniauth'
gem 'omniauth-github'
gem 'omniauth-rails_csrf_protection'
gem 'dotenv-rails'
> Console
$ bundle install

5. Create a .env file within the root directory of your application and insert the values of your github’s omniauth client id and secret as follows:

6. Update our devise.rb file located in our initializers folder with the following line.

initializers/devise.rb

7. Update our routes.rb and insert the following lines into your devise_for :users .

devise_for :users,:controllers => {omniauth_callbacks: 'users/omniauth_callbacks'}

8. Update our devise generated controller omniauth_callbacks_controller.rb and insert the following lines of code.

omniauth_callbacks_controller.rb

9. Update our User model to include the following lines of code.

user.rb

Routes

More Information

For more information about the project, you can view my GitHub.

For a video demonstration about how the project works and what it looks like, you can click on this link.

--

--