mirror of
				https://github.com/fspc/bike-database.git
				synced 2025-10-31 00:35:35 -04:00 
			
		
		
		
	Louis | Adds agencies
This commit is contained in:
		
							parent
							
								
									36e7c1624f
								
							
						
					
					
						commit
						7ed3fce648
					
				
							
								
								
									
										57
									
								
								app/controllers/agencies_controller.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								app/controllers/agencies_controller.rb
									
									
									
									
									
										Normal file
									
								
							| @ -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 | ||||
							
								
								
									
										2
									
								
								app/models/agency.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								app/models/agency.rb
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | ||||
| class Agency < ActiveRecord::Base | ||||
| end | ||||
							
								
								
									
										42
									
								
								app/views/agencies/_fields.html.haml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								app/views/agencies/_fields.html.haml
									
									
									
									
									
										Normal file
									
								
							| @ -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 | ||||
| 
 | ||||
							
								
								
									
										11
									
								
								app/views/agencies/_form.html.haml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								app/views/agencies/_form.html.haml
									
									
									
									
									
										Normal file
									
								
							| @ -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" | ||||
							
								
								
									
										6
									
								
								app/views/agencies/edit.html.haml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								app/views/agencies/edit.html.haml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | ||||
| .container | ||||
|   %h1 Edit Agency  | ||||
|   = render 'form'  | ||||
|   = link_to 'Show', @agency | ||||
|   | | ||||
|   = link_to 'Back', agencies_path | ||||
							
								
								
									
										20
									
								
								app/views/agencies/index.html.haml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								app/views/agencies/index.html.haml
									
									
									
									
									
										Normal file
									
								
							| @ -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" | ||||
							
								
								
									
										4
									
								
								app/views/agencies/new.html.haml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								app/views/agencies/new.html.haml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | ||||
| .container | ||||
|   %h1 New Agency | ||||
|   = render 'form' | ||||
|   = link_to 'Back', agencies_path | ||||
							
								
								
									
										7
									
								
								app/views/agencies/show.html.haml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								app/views/agencies/show.html.haml
									
									
									
									
									
										Normal file
									
								
							| @ -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 | ||||
| @ -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  | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| .container | ||||
|   %h1 Editing client | ||||
|   %h1 Edit client | ||||
|   = render 'form'  | ||||
|   = link_to 'Show', @client | ||||
|   | | ||||
|  | ||||
| @ -10,3 +10,5 @@ | ||||
|   = link_to "Clients", clients_path | ||||
|   %br | ||||
|   = link_to "Print Bikes", print_select_bikes_path | ||||
|   %br | ||||
|   = link_to "Agencies", agencies_path | ||||
|  | ||||
| @ -9,5 +9,6 @@ Bikedb::Application.routes.draw do | ||||
|   end | ||||
| 
 | ||||
|   resources :volunteers | ||||
|   resources :agencies | ||||
|   resources :clients | ||||
| end | ||||
|  | ||||
							
								
								
									
										14
									
								
								db/migrate/20140921225115_create_agencies_table.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								db/migrate/20140921225115_create_agencies_table.rb
									
									
									
									
									
										Normal file
									
								
							| @ -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 | ||||
							
								
								
									
										13
									
								
								db/schema.rb
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								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" | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user