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..3dc5ebc --- /dev/null +++ b/app/controllers/courses_controller.rb @@ -0,0 +1,54 @@ +# 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 + 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 new file mode 100644 index 0000000..58e834a --- /dev/null +++ b/app/models/course.rb @@ -0,0 +1,12 @@ +# 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 + 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..57226c0 --- /dev/null +++ b/app/views/courses/_form.html.erb @@ -0,0 +1,42 @@ + + +<%= form_with model: @course, local: true do |form| %> + <% if @course.errors.any? %> +
+

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

+ +
+ <% 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..74e0de1 --- /dev/null +++ b/app/views/courses/edit.html.erb @@ -0,0 +1,17 @@ + + +

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..9a3d35a --- /dev/null +++ b/app/views/courses/index.html.erb @@ -0,0 +1,34 @@ + + +

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..ef492b1 --- /dev/null +++ b/app/views/courses/new.html.erb @@ -0,0 +1,17 @@ + + +

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..436cf84 --- /dev/null +++ b/app/views/courses/show.html.erb @@ -0,0 +1,27 @@ + + +

+ 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/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/doc/CodingStandards.md b/doc/CodingStandards.md new file mode 100644 index 0000000..c1c7755 --- /dev/null +++ b/doc/CodingStandards.md @@ -0,0 +1,17 @@ +# 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 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. 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 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