From 39ff4cf5627307bf52c541e15b86c5490f5f7c63 Mon Sep 17 00:00:00 2001 From: jere99 Date: Tue, 8 Jan 2019 00:08:16 -0500 Subject: [PATCH 1/7] Create basic course model --- app/models/course.rb | 2 ++ db/migrate/20190108045520_create_courses.rb | 11 ++++++++++ db/schema.rb | 23 +++++++++++++++++++++ test/fixtures/courses.yml | 11 ++++++++++ test/models/course_test.rb | 7 +++++++ 5 files changed, 54 insertions(+) create mode 100644 app/models/course.rb create mode 100644 db/migrate/20190108045520_create_courses.rb create mode 100644 db/schema.rb create mode 100644 test/fixtures/courses.yml create mode 100644 test/models/course_test.rb diff --git a/app/models/course.rb b/app/models/course.rb new file mode 100644 index 0000000..25e8ed7 --- /dev/null +++ b/app/models/course.rb @@ -0,0 +1,2 @@ +class Course < ApplicationRecord +end diff --git a/db/migrate/20190108045520_create_courses.rb b/db/migrate/20190108045520_create_courses.rb new file mode 100644 index 0000000..3b1f44b --- /dev/null +++ b/db/migrate/20190108045520_create_courses.rb @@ -0,0 +1,11 @@ +class CreateCourses < ActiveRecord::Migration[5.2] + def change + create_table :courses do |t| + t.string :title + t.string :abbreviation + t.string :teacher + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..5b91f0e --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,23 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 2019_01_08_045520) do + + create_table "courses", force: :cascade do |t| + t.string "title" + t.string "abbreviation" + t.string "teacher" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end diff --git a/test/fixtures/courses.yml b/test/fixtures/courses.yml new file mode 100644 index 0000000..3c5abce --- /dev/null +++ b/test/fixtures/courses.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + title: MyString + abbreviation: MyString + teacher: MyString + +two: + title: MyString + abbreviation: MyString + teacher: MyString diff --git a/test/models/course_test.rb b/test/models/course_test.rb new file mode 100644 index 0000000..4afb5cd --- /dev/null +++ b/test/models/course_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CourseTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From 16e9a4c69aa9704b8e4e11766efb92a90b20bedf Mon Sep 17 00:00:00 2001 From: jere99 Date: Tue, 29 Jan 2019 00:08:32 -0500 Subject: [PATCH 2/7] Add full course controller with all relevant actions and basic views --- app/assets/javascripts/courses.coffee | 3 ++ app/assets/stylesheets/courses.scss | 3 ++ app/controllers/courses_controller.rb | 47 +++++++++++++++++++++ app/helpers/courses_helper.rb | 2 + app/models/course.rb | 3 ++ app/views/courses/_form.html.erb | 30 +++++++++++++ app/views/courses/edit.html.erb | 5 +++ app/views/courses/index.html.erb | 22 ++++++++++ app/views/courses/new.html.erb | 5 +++ app/views/courses/show.html.erb | 15 +++++++ config/routes.rb | 3 ++ test/controllers/courses_controller_test.rb | 7 +++ 12 files changed, 145 insertions(+) create mode 100644 app/assets/javascripts/courses.coffee create mode 100644 app/assets/stylesheets/courses.scss create mode 100644 app/controllers/courses_controller.rb create mode 100644 app/helpers/courses_helper.rb create mode 100644 app/views/courses/_form.html.erb create mode 100644 app/views/courses/edit.html.erb create mode 100644 app/views/courses/index.html.erb create mode 100644 app/views/courses/new.html.erb create mode 100644 app/views/courses/show.html.erb create mode 100644 test/controllers/courses_controller_test.rb diff --git a/app/assets/javascripts/courses.coffee b/app/assets/javascripts/courses.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/courses.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/courses.scss b/app/assets/stylesheets/courses.scss new file mode 100644 index 0000000..69ef4ef --- /dev/null +++ b/app/assets/stylesheets/courses.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Courses controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb new file mode 100644 index 0000000..ad32ee2 --- /dev/null +++ b/app/controllers/courses_controller.rb @@ -0,0 +1,47 @@ +class CoursesController < ApplicationController + def index + @courses = Course.all + end + + def show + @course = Course.find(params[:id]) + end + + def new + @course = Course.new + end + + def edit + @course = Course.find(params[:id]) + end + + def create + @course = Course.new(course_params) + if @course.save + redirect_to @course + else + render 'new' + end + end + + def update + @course = Course.find(params[:id]) + if @course.update(course_params) + redirect_to @course + else + render 'edit' + end + end + + def destroy + @course = Course.find(params[:id]) + @course.destroy + + redirect_to courses_path + end + + private + def course_params + params.require(:course).permit(:title, :abbreviation, :teacher) + end +end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb new file mode 100644 index 0000000..c159f1e --- /dev/null +++ b/app/helpers/courses_helper.rb @@ -0,0 +1,2 @@ +module CoursesHelper +end diff --git a/app/models/course.rb b/app/models/course.rb index 25e8ed7..cfe8eab 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -1,2 +1,5 @@ class Course < ApplicationRecord + validates :title, presence: true + validates :abbreviation, presence: true + validates :teacher, presence: true end diff --git a/app/views/courses/_form.html.erb b/app/views/courses/_form.html.erb new file mode 100644 index 0000000..df1f44b --- /dev/null +++ b/app/views/courses/_form.html.erb @@ -0,0 +1,30 @@ +<%= form_with model: @course, local: true do |form| %> + <% if @course.errors.any? %> +
+

+ <%= pluralize(@course.errors.count, "error") %> prohibited this course from being saved: +

+
    + <% @course.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> + +

+ <%= form.label :title %>
+ <%= form.text_field :title %> +

+

+ <%= form.label :abbreviation %>
+ <%= form.text_field :abbreviation %> +

+

+ <%= form.label :teacher %>
+ <%= form.text_field :teacher %> +

+

+ <%= form.submit %> +

+<% end %> diff --git a/app/views/courses/edit.html.erb b/app/views/courses/edit.html.erb new file mode 100644 index 0000000..e55505c --- /dev/null +++ b/app/views/courses/edit.html.erb @@ -0,0 +1,5 @@ +

Edit Course

+ +<%= render 'form' %> + +<%= link_to 'Back', courses_path %> diff --git a/app/views/courses/index.html.erb b/app/views/courses/index.html.erb new file mode 100644 index 0000000..2e8f963 --- /dev/null +++ b/app/views/courses/index.html.erb @@ -0,0 +1,22 @@ +

All Courses

+ +<%= link_to 'New Course', new_course_path %> + + + + + + + + + <% @courses.each do |course| %> + + + + + + + + + <% end %> +
TitleAbbreviationTeacher
<%= course.title %><%= course.abbreviation %><%= course.teacher %><%= link_to 'Show', course_path(course) %><%= link_to 'Edit', edit_course_path(course) %><%= link_to 'Destroy', course_path(course), method: :delete, data: { confirm: 'Are you sure?' } %>
diff --git a/app/views/courses/new.html.erb b/app/views/courses/new.html.erb new file mode 100644 index 0000000..abfb787 --- /dev/null +++ b/app/views/courses/new.html.erb @@ -0,0 +1,5 @@ +

New Course

+ +<%= render 'form' %> + +<%= link_to 'Back', courses_path %> diff --git a/app/views/courses/show.html.erb b/app/views/courses/show.html.erb new file mode 100644 index 0000000..294d4a4 --- /dev/null +++ b/app/views/courses/show.html.erb @@ -0,0 +1,15 @@ +

+ Title: + <%= @course.title %> +

+

+ Abbreviation: + <%= @course.abbreviation %> +

+

+ Teacher: + <%= @course.teacher %> +

+ +<%= link_to 'Edit', edit_course_path(@course) %> | +<%= link_to 'Back', courses_path %> diff --git a/config/routes.rb b/config/routes.rb index 787824f..ebabf72 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,6 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + + resources :courses + end diff --git a/test/controllers/courses_controller_test.rb b/test/controllers/courses_controller_test.rb new file mode 100644 index 0000000..4b55772 --- /dev/null +++ b/test/controllers/courses_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CoursesControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end From cc462235e752aa5fbe9d875624fa24302e98125e Mon Sep 17 00:00:00 2001 From: jere99 Date: Sun, 3 Feb 2019 14:41:38 -0500 Subject: [PATCH 3/7] Change Tab Length --- app/controllers/courses_controller.rb | 90 +++++++++++++-------------- app/models/course.rb | 6 +- app/views/courses/_form.html.erb | 54 ++++++++-------- app/views/courses/index.html.erb | 32 +++++----- app/views/courses/show.html.erb | 12 ++-- 5 files changed, 97 insertions(+), 97 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index ad32ee2..55ee53b 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1,47 +1,47 @@ class CoursesController < ApplicationController - def index - @courses = Course.all - end - - def show - @course = Course.find(params[:id]) - end - - def new - @course = Course.new - end - - def edit - @course = Course.find(params[:id]) - end - - def create - @course = Course.new(course_params) - if @course.save - redirect_to @course - else - render 'new' - end - end - - def update - @course = Course.find(params[:id]) - if @course.update(course_params) - redirect_to @course - else - render 'edit' - end - end - - def destroy - @course = Course.find(params[:id]) - @course.destroy - - redirect_to courses_path - end - - private - def course_params - params.require(:course).permit(:title, :abbreviation, :teacher) - end + def index + @courses = Course.all + end + + def show + @course = Course.find(params[:id]) + end + + def new + @course = Course.new + end + + def edit + @course = Course.find(params[:id]) + end + + def create + @course = Course.new(course_params) + if @course.save + redirect_to @course + else + render 'new' + end + end + + def update + @course = Course.find(params[:id]) + if @course.update(course_params) + redirect_to @course + else + render 'edit' + end + end + + def destroy + @course = Course.find(params[:id]) + @course.destroy + + redirect_to courses_path + end + + private + def course_params + params.require(:course).permit(:title, :abbreviation, :teacher) + end end diff --git a/app/models/course.rb b/app/models/course.rb index cfe8eab..5eedc90 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -1,5 +1,5 @@ class Course < ApplicationRecord - validates :title, presence: true - validates :abbreviation, presence: true - validates :teacher, presence: true + validates :title, presence: true + validates :abbreviation, presence: true + validates :teacher, presence: true end diff --git a/app/views/courses/_form.html.erb b/app/views/courses/_form.html.erb index df1f44b..349575a 100644 --- a/app/views/courses/_form.html.erb +++ b/app/views/courses/_form.html.erb @@ -1,30 +1,30 @@ <%= form_with model: @course, local: true do |form| %> - <% if @course.errors.any? %> -
-

- <%= pluralize(@course.errors.count, "error") %> prohibited this course from being saved: -

-
    - <% @course.errors.full_messages.each do |msg| %> -
  • <%= msg %>
  • - <% end %> -
-
- <% end %> + <% if @course.errors.any? %> +
+

+ <%= pluralize(@course.errors.count, "error") %> prohibited this course from being saved: +

+
    + <% @course.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> -

- <%= form.label :title %>
- <%= form.text_field :title %> -

-

- <%= form.label :abbreviation %>
- <%= form.text_field :abbreviation %> -

-

- <%= form.label :teacher %>
- <%= form.text_field :teacher %> -

-

- <%= form.submit %> -

+

+ <%= form.label :title %>
+ <%= form.text_field :title %> +

+

+ <%= form.label :abbreviation %>
+ <%= form.text_field :abbreviation %> +

+

+ <%= form.label :teacher %>
+ <%= form.text_field :teacher %> +

+

+ <%= form.submit %> +

<% end %> diff --git a/app/views/courses/index.html.erb b/app/views/courses/index.html.erb index 2e8f963..f1f0892 100644 --- a/app/views/courses/index.html.erb +++ b/app/views/courses/index.html.erb @@ -3,20 +3,20 @@ <%= link_to 'New Course', new_course_path %> - - - - - - - <% @courses.each do |course| %> - - - - - - - - - <% end %> + + + + + + + <% @courses.each do |course| %> + + + + + + + + + <% end %>
TitleAbbreviationTeacher
<%= course.title %><%= course.abbreviation %><%= course.teacher %><%= link_to 'Show', course_path(course) %><%= link_to 'Edit', edit_course_path(course) %><%= link_to 'Destroy', course_path(course), method: :delete, data: { confirm: 'Are you sure?' } %>
TitleAbbreviationTeacher
<%= course.title %><%= course.abbreviation %><%= course.teacher %><%= link_to 'Show', course_path(course) %><%= link_to 'Edit', edit_course_path(course) %><%= link_to 'Destroy', course_path(course), method: :delete, data: { confirm: 'Are you sure?' } %>
diff --git a/app/views/courses/show.html.erb b/app/views/courses/show.html.erb index 294d4a4..c987609 100644 --- a/app/views/courses/show.html.erb +++ b/app/views/courses/show.html.erb @@ -1,14 +1,14 @@

- Title: - <%= @course.title %> + Title: + <%= @course.title %>

- Abbreviation: - <%= @course.abbreviation %> + Abbreviation: + <%= @course.abbreviation %>

- Teacher: - <%= @course.teacher %> + Teacher: + <%= @course.teacher %>

<%= link_to 'Edit', edit_course_path(@course) %> | From 80883c16cc1dcbbcf31e5e51a389e3c2c6408e62 Mon Sep 17 00:00:00 2001 From: jere99 Date: Tue, 9 Apr 2019 00:23:20 -0400 Subject: [PATCH 4/7] Create guidelines file --- doc/CodingStandards.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 doc/CodingStandards.md diff --git a/doc/CodingStandards.md b/doc/CodingStandards.md new file mode 100644 index 0000000..e1f5567 --- /dev/null +++ b/doc/CodingStandards.md @@ -0,0 +1,14 @@ +# VirtualPlanner Coding Standards + +This document is not yet complete, but these are the standards we have established thus far. + +## General Style Guide +- We have chosen to conform to the ruby standard of soft tabs with a length of two spaces. Please set your editor to this tab length, so that no issues will arise. +- All lines should have no trailing whitespace. +- All files should end with a newline character. + +## Style Guide for Ruby Files +- All ruby files that are not automatically generated should include a block comment at the top of the file specifying the purpose of the file, all authors of the file, the creation date, and the date of the last modification. +- Use snake_case for methods and variables. +- Use CamelCase for classes and modules. +- Use double quotes for strings in all cases. From 5e601f1a21d91f0854898747891da58466f16976 Mon Sep 17 00:00:00 2001 From: jere99 Date: Tue, 9 Apr 2019 19:13:32 -0400 Subject: [PATCH 5/7] update CodingStandards.md --- doc/CodingStandards.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/CodingStandards.md b/doc/CodingStandards.md index e1f5567..c1c7755 100644 --- a/doc/CodingStandards.md +++ b/doc/CodingStandards.md @@ -11,4 +11,7 @@ This document is not yet complete, but these are the standards we have establish - All ruby files that are not automatically generated should include a block comment at the top of the file specifying the purpose of the file, all authors of the file, the creation date, and the date of the last modification. - Use snake_case for methods and variables. - Use CamelCase for classes and modules. -- Use double quotes for strings in all cases. +- Use double quotes for string literals unless automatically generated. + +## Style Guide for Embedded Ruby Files +- All embedded ruby files should include a block comment at the top of the file specifying the purpose of the file, all authors of the file, the creation date, the date of the last modification, and an example context. From 4aa247cdb7b93770829a11d62682e6aea5a5957c Mon Sep 17 00:00:00 2001 From: jere99 Date: Tue, 9 Apr 2019 19:16:32 -0400 Subject: [PATCH 6/7] comments for ruby files --- app/controllers/courses_controller.rb | 11 +++++++++-- app/models/course.rb | 7 +++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 55ee53b..3dc5ebc 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1,3 +1,10 @@ +# This is the Controller for the Course model. +# +# Authors: +# Jeremiah DeGreeff +# Created on 1/29/2019 +# Last Modified 4/9/2019 + class CoursesController < ApplicationController def index @courses = Course.all @@ -20,7 +27,7 @@ def create if @course.save redirect_to @course else - render 'new' + render "new" end end @@ -29,7 +36,7 @@ def update if @course.update(course_params) redirect_to @course else - render 'edit' + render "edit" end end diff --git a/app/models/course.rb b/app/models/course.rb index 5eedc90..58e834a 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -1,3 +1,10 @@ +# This is the model for a Course. +# +# Authors: +# Jeremiah DeGreeff +# Created on 1/8/2019 +# Last Modified 4/9/2019 + class Course < ApplicationRecord validates :title, presence: true validates :abbreviation, presence: true From b197caaaf8056f33761c6e1e7dc97c875653f8b8 Mon Sep 17 00:00:00 2001 From: jere99 Date: Mon, 13 May 2019 22:35:42 -0400 Subject: [PATCH 7/7] comments for the existing views long overdue --- app/views/courses/_form.html.erb | 12 ++++++++++++ app/views/courses/edit.html.erb | 12 ++++++++++++ app/views/courses/index.html.erb | 12 ++++++++++++ app/views/courses/new.html.erb | 12 ++++++++++++ app/views/courses/show.html.erb | 12 ++++++++++++ 5 files changed, 60 insertions(+) diff --git a/app/views/courses/_form.html.erb b/app/views/courses/_form.html.erb index 349575a..57226c0 100644 --- a/app/views/courses/_form.html.erb +++ b/app/views/courses/_form.html.erb @@ -1,3 +1,15 @@ + + <%= form_with model: @course, local: true do |form| %> <% if @course.errors.any? %>
diff --git a/app/views/courses/edit.html.erb b/app/views/courses/edit.html.erb index e55505c..74e0de1 100644 --- a/app/views/courses/edit.html.erb +++ b/app/views/courses/edit.html.erb @@ -1,3 +1,15 @@ + +

Edit Course

<%= render 'form' %> diff --git a/app/views/courses/index.html.erb b/app/views/courses/index.html.erb index f1f0892..9a3d35a 100644 --- a/app/views/courses/index.html.erb +++ b/app/views/courses/index.html.erb @@ -1,3 +1,15 @@ + +

All Courses

<%= link_to 'New Course', new_course_path %> diff --git a/app/views/courses/new.html.erb b/app/views/courses/new.html.erb index abfb787..ef492b1 100644 --- a/app/views/courses/new.html.erb +++ b/app/views/courses/new.html.erb @@ -1,3 +1,15 @@ + +

New Course

<%= render 'form' %> diff --git a/app/views/courses/show.html.erb b/app/views/courses/show.html.erb index c987609..436cf84 100644 --- a/app/views/courses/show.html.erb +++ b/app/views/courses/show.html.erb @@ -1,3 +1,15 @@ + +

Title: <%= @course.title %>