recipient lists

This commit is contained in:
Jared Cosulich 2017-03-02 12:00:40 -05:00
parent ab6cefd055
commit 37e01c024b
24 changed files with 491 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 recipient_lists 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 RecipientListsController < ApplicationController
before_action :set_school
before_action :set_recipient_list, only: [:show, :edit, :update, :destroy]
# GET schools/1/recipient_lists
def index
@recipient_lists = @school.recipient_lists
end
# GET schools/1/recipient_lists/1
def show
end
# GET schools/1/recipient_lists/new
def new
@recipient_list = @school.recipient_lists.build
end
# GET schools/1/recipient_lists/1/edit
def edit
end
# POST schools/1/recipient_lists
def create
@recipient_list = @school.recipient_lists.build(recipient_list_params)
if @recipient_list.save
redirect_to([@recipient_list.school, @recipient_list], notice: 'Recipient list was successfully created.')
else
render action: 'new'
end
end
# PUT schools/1/recipient_lists/1
def update
if @recipient_list.update_attributes(recipient_list_params)
redirect_to([@recipient_list.school, @recipient_list], notice: 'Recipient list was successfully updated.')
else
render action: 'edit'
end
end
# DELETE schools/1/recipient_lists/1
def destroy
@recipient_list.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_recipient_list
@recipient_list = @school.recipient_lists.find(params[:id])
end
# Only allow a trusted parameter "white list" through.
def recipient_list_params
params.require(:recipient_list).permit(:name, :description, :recipient_ids)
end
end

View file

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

View file

@ -0,0 +1,6 @@
class RecipientList < ApplicationRecord
belongs_to :school
validates :name, presence: true
validates :recipient_ids, presence: true
end

View file

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

View file

@ -0,0 +1,23 @@
= form_for([@school, @recipient_list]) do |f|
- if @recipient_list.errors.any?
#error_explanation
%h2
= pluralize(@recipient_list.errors.count, "error")
prohibited this recipient_list from being saved:
%ul
- @recipient_list.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 :recipient_ids
%br/
= f.text_area :recipient_ids
.actions
= f.submit

View file

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

View file

@ -0,0 +1,19 @@
%h1 Listing recipient_lists
%table
%tr
%th Name
%th Description
%th Recipient ids
%th
%th
%th
- @recipient_lists.each do |recipient_list|
%tr
%td= recipient_list.name
%td= recipient_list.description
%td= recipient_list.recipient_ids
%td= link_to 'Show', [recipient_list.school, recipient_list]
%td= link_to 'Edit', edit_school_recipient_list_path(recipient_list.school, recipient_list)
%td= link_to 'Destroy', [recipient_list.school, recipient_list], :confirm => 'Are you sure?', :method => :delete
%br/
= link_to 'New Recipient list', new_school_recipient_list_path(@school)

View file

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

View file

@ -0,0 +1,13 @@
%p#notice= notice
%p
%b Name:
= @recipient_list.name
%p
%b Description:
= @recipient_list.description
%p
%b Recipient ids:
= @recipient_list.recipient_ids
= link_to 'Edit', edit_school_recipient_list_path(@recipient_list.school, @recipient_list)
|
= link_to 'Back', school_recipient_lists_path(@recipient_list.school)

View file

@ -0,0 +1,4 @@
json.array!(@school_recipient_lists) do |school_recipient_list|
json.extract! school_recipient_list, :id, :name, :description, :recipient_ids
json.url school_recipient_list_url(school_recipient_list, format: :json)
end

View file

@ -0,0 +1 @@
json.extract! @school_recipient_list, :id, :name, :description, :recipient_ids, :created_at, :updated_at