working on schedules

This commit is contained in:
Jared Cosulich 2017-03-06 11:35:29 -05:00
parent 72418edd7c
commit 2fb55a7443
26 changed files with 726 additions and 1 deletions

View file

@ -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/

View file

@ -0,0 +1,3 @@
// Place all the styles related to the schedules controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View file

@ -0,0 +1,64 @@
class SchedulesController < ApplicationController
before_action :set_school
before_action :set_schedule, only: [:show, :edit, :update, :destroy]
# GET schools/1/schedules
def index
@schedules = @school.schedules
end
# GET schools/1/schedules/1
def show
end
# GET schools/1/schedules/new
def new
@schedule = @school.schedules.build
end
# GET schools/1/schedules/1/edit
def edit
end
# POST schools/1/schedules
def create
@schedule = @school.schedules.build(schedule_params)
if @schedule.save
redirect_to([@schedule.school, @schedule], notice: 'Schedule was successfully created.')
else
render action: 'new'
end
end
# PUT schools/1/schedules/1
def update
if @schedule.update_attributes(schedule_params)
redirect_to([@schedule.school, @schedule], notice: 'Schedule was successfully updated.')
else
render action: 'edit'
end
end
# DELETE schools/1/schedules/1
def destroy
@schedule.destroy
redirect_to @school
end
private
# Use callbacks to share common setup or constraints between actions.
def set_school
@school = School.find(params[:school_id])
end
def set_schedule
@schedule = @school.schedules.find(params[:id])
end
# Only allow a trusted parameter "white list" through.
def schedule_params
params.require(:schedule).permit(:name, :description, :school_id, :frequency_hours, :start_date, :end_date, :active, :random, :recipient_list_id, :question_list_id)
end
end

View file

@ -0,0 +1,2 @@
module SchedulesHelper
end

11
app/models/schedule.rb Normal file
View file

@ -0,0 +1,11 @@
class Schedule < ApplicationRecord
belongs_to :school
belongs_to :recipient_list
belongs_to :question_list
validates :name, presence: true
validates :recipient_list, presence: true
validates :question_list, presence: true
end

View file

@ -1,4 +1,5 @@
class School < ApplicationRecord
has_many :schedules
has_many :recipient_lists
belongs_to :district
has_many :recipients

View file

@ -0,0 +1,51 @@
= form_for([@schedule.school, @schedule]) do |f|
- if @schedule.errors.any?
#error_explanation
%h2
= pluralize(@schedule.errors.count, "error")
prohibited this schedule from being saved:
%ul
- @schedule.errors.full_messages.each do |msg|
%li= msg
.field
= f.label :name
%br/
= f.text_field :name
.field
= f.label :description
%br/
= f.text_area :description
.field
= f.label :school_id
%br/
= f.number_field :school_id
.field
= f.label :frequency_hours
%br/
= f.number_field :frequency_hours
.field
= f.label :start_date
%br/
= f.date_select :start_date
.field
= f.label :end_date
%br/
= f.date_select :end_date
.field
= f.label :active
%br/
= f.check_box :active
.field
= f.label :random
%br/
= f.check_box :random
.field
= f.label :recipient_list_id
%br/
= f.number_field :recipient_list_id
.field
= f.label :question_list_id
%br/
= f.number_field :question_list_id
.actions
= f.submit

View file

@ -0,0 +1,5 @@
%h1 Editing schedule
= render 'form'
= link_to 'Show', [@schedule.school, @schedule]
|
= link_to 'Back', school_schedules_path(@schedule.school)

View file

@ -0,0 +1,33 @@
%h1 Listing schedules
%table
%tr
%th Name
%th Description
%th School
%th Frequency hours
%th Start date
%th End date
%th Active
%th Random
%th Recipient list
%th Question list
%th
%th
%th
- @schedules.each do |schedule|
%tr
%td= schedule.name
%td= schedule.description
%td= schedule.school.name
%td= schedule.frequency_hours
%td= schedule.start_date
%td= schedule.end_date
%td= schedule.active
%td= schedule.random
%td= schedule.recipient_list.name
%td= schedule.question_list.name
%td= link_to 'Show', [schedule.school, schedule]
%td= link_to 'Edit', edit_school_schedule_path(schedule.school, schedule)
%td= link_to 'Destroy', [schedule.school, schedule], :confirm => 'Are you sure?', :method => :delete
%br/
= link_to 'New Schedule', new_school_schedule_path(@school)

View file

@ -0,0 +1,3 @@
%h1 New schedule
= render 'form'
= link_to 'Back', school_schedules_path(@schedule.school)

View file

@ -0,0 +1,34 @@
%p#notice= notice
%p
%b Name:
= @schedule.name
%p
%b Description:
= @schedule.description
%p
%b School:
= @schedule.school.name
%p
%b Frequency hours:
= @schedule.frequency_hours
%p
%b Start date:
= @schedule.start_date
%p
%b End date:
= @schedule.end_date
%p
%b Active:
= @schedule.active
%p
%b Random:
= @schedule.random
%p
%b Recipient list:
= @schedule.recipient_list.name
%p
%b Question list:
= @schedule.question_list.name
= link_to 'Edit', edit_school_schedule_path(@schedule.school, @schedule)
|
= link_to 'Back', school_schedules_path(@schedule.school)

View file

@ -0,0 +1,4 @@
json.array!(@school_schedules) do |school_schedule|
json.extract! school_schedule, :id, :name, :description, :school_id, :frequency_hours, :start_date, :end_date, :active, :random, :recipient_list_id, :question_list_id
json.url school_schedule_url(school_schedule, format: :json)
end

View file

@ -0,0 +1 @@
json.extract! @school_schedule, :id, :name, :description, :school_id, :frequency_hours, :start_date, :end_date, :active, :random, :recipient_list_id, :question_list_id, :created_at, :updated_at