Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/assets/javascripts/courses.coffee
Original file line number Diff line number Diff line change
@@ -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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/courses.scss
Original file line number Diff line number Diff line change
@@ -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/
54 changes: 54 additions & 0 deletions app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions app/helpers/courses_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CoursesHelper
end
12 changes: 12 additions & 0 deletions app/models/course.rb
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions app/views/courses/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!--
This is the partial for the course form.

Authors:
Jeremiah DeGreeff
Created on 1/29/2019
Last Modified 5/13/2019

Example Context:
@course A Course object, could be new or have existing data.
-->

<%= form_with model: @course, local: true do |form| %>
<% if @course.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(@course.errors.count, "error") %> prohibited this course from being saved:
</h2>
<ul>
<% @course.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<p>
<%= form.label :title %><br>
<%= form.text_field :title %>
</p>
<p>
<%= form.label :abbreviation %><br>
<%= form.text_field :abbreviation %>
</p>
<p>
<%= form.label :teacher %><br>
<%= form.text_field :teacher %>
</p>
<p>
<%= form.submit %>
</p>
<% end %>
17 changes: 17 additions & 0 deletions app/views/courses/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!--
This is the view for the course edit page.

Authors:
Jeremiah DeGreeff
Created on 1/29/2019
Last Modified 5/13/2019

Example Context:
@course A Course object with existing data.
-->

<h1>Edit Course</h1>

<%= render 'form' %>

<%= link_to 'Back', courses_path %>
34 changes: 34 additions & 0 deletions app/views/courses/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!--
This is the view for the course index page.

Authors:
Jeremiah DeGreeff
Created on 1/29/2019
Last Modified 5/13/2019

Example Context:
@courses An array of all of the Course objects in the database.
-->

<h1>All Courses</h1>

<%= link_to 'New Course', new_course_path %>

<table>
<tr>
<th>Title</th>
<th>Abbreviation</th>
<th>Teacher</th>
<th colspan="3"></th>
</tr>
<% @courses.each do |course| %>
<tr>
<td><%= course.title %></td>
<td><%= course.abbreviation %></td>
<td><%= course.teacher %></td>
<td><%= link_to 'Show', course_path(course) %></td>
<td><%= link_to 'Edit', edit_course_path(course) %></td>
<td><%= link_to 'Destroy', course_path(course), method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
17 changes: 17 additions & 0 deletions app/views/courses/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!--
This is the view for the new course page.

Authors:
Jeremiah DeGreeff
Created on 1/29/2019
Last Modified 5/13/2019

Example Context:
@course A new Course object.
-->

<h1>New Course</h1>

<%= render 'form' %>

<%= link_to 'Back', courses_path %>
27 changes: 27 additions & 0 deletions app/views/courses/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!--
This is the view for a course page.

Authors:
Jeremiah DeGreeff
Created on 1/29/2019
Last Modified 5/13/2019

Example Context:
@course A Course object to be displayed.
-->

<p>
<strong>Title:</strong>
<%= @course.title %>
</p>
<p>
<strong>Abbreviation:</strong>
<%= @course.abbreviation %>
</p>
<p>
<strong>Teacher:</strong>
<%= @course.teacher %>
</p>

<%= link_to 'Edit', edit_course_path(@course) %> |
<%= link_to 'Back', courses_path %>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions db/migrate/20190108045520_create_courses.rb
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions doc/CodingStandards.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions test/controllers/courses_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class CoursesControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
11 changes: 11 additions & 0 deletions test/fixtures/courses.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions test/models/course_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class CourseTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end