From 7ed3fce648954fd4e2b85790d7e184c580a96f62 Mon Sep 17 00:00:00 2001 From: Loos Date: Sun, 21 Sep 2014 18:23:15 -0500 Subject: [PATCH] Louis | Adds agencies --- app/controllers/agencies_controller.rb | 57 +++++++++++++++++++ app/models/agency.rb | 2 + app/views/agencies/_fields.html.haml | 42 ++++++++++++++ app/views/agencies/_form.html.haml | 11 ++++ app/views/agencies/edit.html.haml | 6 ++ app/views/agencies/index.html.haml | 20 +++++++ app/views/agencies/new.html.haml | 4 ++ app/views/agencies/show.html.haml | 7 +++ app/views/clients/_form.html.haml | 2 +- app/views/clients/edit.html.haml | 2 +- app/views/static_pages/home.html.haml | 2 + config/routes.rb | 1 + .../20140921225115_create_agencies_table.rb | 14 +++++ db/schema.rb | 13 ++++- 14 files changed, 180 insertions(+), 3 deletions(-) create mode 100644 app/controllers/agencies_controller.rb create mode 100644 app/models/agency.rb create mode 100644 app/views/agencies/_fields.html.haml create mode 100644 app/views/agencies/_form.html.haml create mode 100644 app/views/agencies/edit.html.haml create mode 100644 app/views/agencies/index.html.haml create mode 100644 app/views/agencies/new.html.haml create mode 100644 app/views/agencies/show.html.haml create mode 100644 db/migrate/20140921225115_create_agencies_table.rb diff --git a/app/controllers/agencies_controller.rb b/app/controllers/agencies_controller.rb new file mode 100644 index 0000000..77f79f2 --- /dev/null +++ b/app/controllers/agencies_controller.rb @@ -0,0 +1,57 @@ +class AgenciesController < ApplicationController + before_action :set_agency, only: [:show, :edit, :update, :destroy] + before_action :authenticate_user! + + def index + @agencies = Agency.all + end + + def show + end + + def new + @agency = Agency.new + end + + def edit + end + + def create + @agency = Agency.new(agency_params) + if @agency.save + redirect_to @agency, notice: 'Agency was successfully created.' + else + render action: 'new' + end + end + + def update + if @agency.update(agency_params) + redirect_to @agency, notice: 'Agency was successfully updated.' + else + render action: 'edit' + end + end + + def destroy + @agency.destroy + redirect_to clients_url + end + + private + def set_agency + @agency = Agency.find(params[:id]) + end + + def agency_params + params.require(:agency).permit( + :agency_name, + :contact_name, + :street_address, + :city, + :state, + :postal_code, + :phone_number, + :email) + end +end diff --git a/app/models/agency.rb b/app/models/agency.rb new file mode 100644 index 0000000..41496fb --- /dev/null +++ b/app/models/agency.rb @@ -0,0 +1,2 @@ +class Agency < ActiveRecord::Base +end diff --git a/app/views/agencies/_fields.html.haml b/app/views/agencies/_fields.html.haml new file mode 100644 index 0000000..febdb19 --- /dev/null +++ b/app/views/agencies/_fields.html.haml @@ -0,0 +1,42 @@ +- disabled ||= false +.form-horizontal + .form-group + = f.label "Name of Agency:", class: "col-sm-2 control-label" + .col-sm-10 + = f.text_field :agency_name, class: "form-control", disabled: disabled + + .form-group + = f.label "Contact Name:", class: "col-sm-2 control-label" + .col-sm-10 + = f.text_field :contact_name, class: "form-control", disabled: disabled + + .form-group + = f.label "Street Address:", class: "col-sm-2 control-label" + .col-sm-10 + = f.text_field :street_address, class: "form-control", disabled: disabled + + .form-group + = f.label "City:", class: "col-sm-2 control-label" + .col-sm-10 + = f.text_field :city, class: "form-control", disabled: disabled + + .form-group + = f.label "State:", class: "col-sm-2 control-label" + .col-sm-10 + = f.text_field :state, class: "form-control", disabled: disabled + + .form-group + = f.label "Postal Code:", class: "col-sm-2 control-label" + .col-sm-10 + = f.text_field :postal_code, class: "form-control", disabled: disabled + + .form-group + = f.label "Phone Number", class: "col-sm-2 control-label" + .col-sm-10 + = f.text_field :phone_number, class: "form-control", disabled: disabled + + .form-group + = f.label "email", class: "col-sm-2 control-label" + .col-sm-10 + = f.text_field :email, class: "form-control", disabled: disabled + diff --git a/app/views/agencies/_form.html.haml b/app/views/agencies/_form.html.haml new file mode 100644 index 0000000..458ed49 --- /dev/null +++ b/app/views/agencies/_form.html.haml @@ -0,0 +1,11 @@ += form_for @agency, html: {class: 'form-horizontal'} do |f| + - if @agency.errors.any? + #error_explanation + %h2= pluralize(@agency.errors.count, "error") + " prohibited this agency from being saved:" + %ul + - @agency.errors.full_messages.each do |msg| + %li= msg + = render 'fields', f: f + .row + .actions.col-sm-offset-2 + = f.submit class: "btn btn-default" diff --git a/app/views/agencies/edit.html.haml b/app/views/agencies/edit.html.haml new file mode 100644 index 0000000..281f2d6 --- /dev/null +++ b/app/views/agencies/edit.html.haml @@ -0,0 +1,6 @@ +.container + %h1 Edit Agency + = render 'form' + = link_to 'Show', @agency + | + = link_to 'Back', agencies_path diff --git a/app/views/agencies/index.html.haml b/app/views/agencies/index.html.haml new file mode 100644 index 0000000..53a238d --- /dev/null +++ b/app/views/agencies/index.html.haml @@ -0,0 +1,20 @@ +.container + %h1 Agencies + + %table.table.table-striped.table-bordered.table-hover + %thead + %tr + %th Agency + %th + %th + %th + %tbody + - @agencies.each do |agency| + %tr + %td= agency.agency_name + %td= link_to 'Show', agency + %td= link_to 'Edit', edit_agency_path(agency) + %td= link_to 'Destroy', agency, method: :delete, data: { confirm: 'Are you sure?' } + + %br + = link_to ' + New Agency', new_agency_path, class: "btn btn-default" diff --git a/app/views/agencies/new.html.haml b/app/views/agencies/new.html.haml new file mode 100644 index 0000000..5ed7ec5 --- /dev/null +++ b/app/views/agencies/new.html.haml @@ -0,0 +1,4 @@ +.container + %h1 New Agency + = render 'form' + = link_to 'Back', agencies_path diff --git a/app/views/agencies/show.html.haml b/app/views/agencies/show.html.haml new file mode 100644 index 0000000..2f35201 --- /dev/null +++ b/app/views/agencies/show.html.haml @@ -0,0 +1,7 @@ +.container + %p#notice= notice + = form_for(@agency) do |f| + = render 'fields', f: f, disabled: true + = link_to 'Edit', edit_agency_path(@agency) + | + = link_to 'Back', agencies_path diff --git a/app/views/clients/_form.html.haml b/app/views/clients/_form.html.haml index b74221e..2f052ae 100644 --- a/app/views/clients/_form.html.haml +++ b/app/views/clients/_form.html.haml @@ -1,7 +1,7 @@ = form_for @client, html: {class: 'form-horizontal'} do |f| - if @client.errors.any? #error_explanation - %h2= pluralize(@client.errors.count, "error") + " prohibited this bike from being saved:" + %h2= pluralize(@client.errors.count, "error") + " prohibited this client from being saved:" %ul - @client.errors.full_messages.each do |msg| %li= msg diff --git a/app/views/clients/edit.html.haml b/app/views/clients/edit.html.haml index 85480dc..c4b78f8 100644 --- a/app/views/clients/edit.html.haml +++ b/app/views/clients/edit.html.haml @@ -1,5 +1,5 @@ .container - %h1 Editing client + %h1 Edit client = render 'form' = link_to 'Show', @client | diff --git a/app/views/static_pages/home.html.haml b/app/views/static_pages/home.html.haml index df07eb3..1282d94 100644 --- a/app/views/static_pages/home.html.haml +++ b/app/views/static_pages/home.html.haml @@ -10,3 +10,5 @@ = link_to "Clients", clients_path %br = link_to "Print Bikes", print_select_bikes_path + %br + = link_to "Agencies", agencies_path diff --git a/config/routes.rb b/config/routes.rb index 3db8192..53c2bae 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,5 +9,6 @@ Bikedb::Application.routes.draw do end resources :volunteers + resources :agencies resources :clients end diff --git a/db/migrate/20140921225115_create_agencies_table.rb b/db/migrate/20140921225115_create_agencies_table.rb new file mode 100644 index 0000000..d5064db --- /dev/null +++ b/db/migrate/20140921225115_create_agencies_table.rb @@ -0,0 +1,14 @@ +class CreateAgenciesTable < ActiveRecord::Migration + def change + create_table :agencies do |t| + t.string :agency_name + t.string :contact_name + t.string :street_address + t.string :city + t.string :state + t.string :postal_code + t.string :phone_number + t.string :email + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 1aaf1a3..b8aecba 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,11 +11,22 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140921224502) do +ActiveRecord::Schema.define(version: 20140921225115) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "agencies", force: true do |t| + t.string "agency_name" + t.string "contact_name" + t.string "street_address" + t.string "city" + t.string "state" + t.string "postal_code" + t.string "phone_number" + t.string "email" + end + create_table "bikes", force: true do |t| t.string "entry_date" t.string "brand"