Loos
10 years ago
14 changed files with 180 additions and 3 deletions
@ -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 |
@ -0,0 +1,2 @@ |
|||
class Agency < ActiveRecord::Base |
|||
end |
@ -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 |
|||
|
@ -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" |
@ -0,0 +1,6 @@ |
|||
.container |
|||
%h1 Edit Agency |
|||
= render 'form' |
|||
= link_to 'Show', @agency |
|||
| |
|||
= link_to 'Back', agencies_path |
@ -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" |
@ -0,0 +1,4 @@ |
|||
.container |
|||
%h1 New Agency |
|||
= render 'form' |
|||
= link_to 'Back', agencies_path |
@ -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 |
@ -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 |
Loading…
Reference in new issue