From 2a33493ff238e08ee488a4839a78528969e58568 Mon Sep 17 00:00:00 2001 From: Loos Date: Mon, 22 Sep 2014 19:44:03 -0400 Subject: [PATCH] Louis | Allows users to associate clients with agencies --- app/controllers/clients_controller.rb | 4 ++-- app/models/agency.rb | 1 + app/models/client.rb | 1 + app/views/clients/_fields.html.haml | 10 +++++----- app/views/clients/index.html.haml | 2 +- db/migrate/20140922232527_add_agency_to_client.rb | 5 +++++ .../20140922233036_remove_agency_string_from_client.rb | 5 +++++ db/schema.rb | 5 +++-- 8 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20140922232527_add_agency_to_client.rb create mode 100644 db/migrate/20140922233036_remove_agency_string_from_client.rb diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb index e427436..5e24234 100644 --- a/app/controllers/clients_controller.rb +++ b/app/controllers/clients_controller.rb @@ -59,8 +59,8 @@ class ClientsController < ApplicationController :weight, :helmet, :lock, - :agency, :completion_date, - :bike_id) + :bike_id, + :agency_id) end end diff --git a/app/models/agency.rb b/app/models/agency.rb index 41496fb..ccb73e2 100644 --- a/app/models/agency.rb +++ b/app/models/agency.rb @@ -1,2 +1,3 @@ class Agency < ActiveRecord::Base + has_many :clients end diff --git a/app/models/client.rb b/app/models/client.rb index 97d3a08..e81eb06 100644 --- a/app/models/client.rb +++ b/app/models/client.rb @@ -1,3 +1,4 @@ class Client < ActiveRecord::Base has_one :bike + belongs_to :agency end diff --git a/app/views/clients/_fields.html.haml b/app/views/clients/_fields.html.haml index ef4f2b0..d675634 100644 --- a/app/views/clients/_fields.html.haml +++ b/app/views/clients/_fields.html.haml @@ -50,11 +50,6 @@ = f.label "Lock", class: "col-sm-2 control-label" .col-sm-10 = f.check_box :lock, disabled: disabled - - .form-group - = f.label "Agency", class: "col-sm-2 control-label" - .col-sm-10 - = f.text_field :agency, class: "form-control", disabled: disabled .form-group = f.label "Completion Date:", class: "col-sm-2 control-label" @@ -66,3 +61,8 @@ .col-sm-10 = f.select(:bike_id, Bike.all.collect {|b| [ b.name, b.id ] }, {include_blank: 'None'}) + .form-group + = f.label "Agency:", class: "col-sm-2 control-label" + .col-sm-10 + = f.select(:agency_id, Agency.all.collect {|b| [ b.agency_name, b.id ] }, {include_blank: 'None'}) + diff --git a/app/views/clients/index.html.haml b/app/views/clients/index.html.haml index a44d381..754bcdc 100644 --- a/app/views/clients/index.html.haml +++ b/app/views/clients/index.html.haml @@ -15,7 +15,7 @@ %tr %td= client.first_name %td= client.last_name - %td= client.agency + %td= client.agency.agency_name if client.agency %td= link_to 'Show', client %td= link_to 'Edit', edit_client_path(client) %td= link_to 'Destroy', client, method: :delete, data: { confirm: 'Are you sure?' } diff --git a/db/migrate/20140922232527_add_agency_to_client.rb b/db/migrate/20140922232527_add_agency_to_client.rb new file mode 100644 index 0000000..fff56d7 --- /dev/null +++ b/db/migrate/20140922232527_add_agency_to_client.rb @@ -0,0 +1,5 @@ +class AddAgencyToClient < ActiveRecord::Migration + def change + add_reference :clients, :agency, index: true + end +end diff --git a/db/migrate/20140922233036_remove_agency_string_from_client.rb b/db/migrate/20140922233036_remove_agency_string_from_client.rb new file mode 100644 index 0000000..a8f3e35 --- /dev/null +++ b/db/migrate/20140922233036_remove_agency_string_from_client.rb @@ -0,0 +1,5 @@ +class RemoveAgencyStringFromClient < ActiveRecord::Migration + def change + remove_column :clients, :agency + end +end diff --git a/db/schema.rb b/db/schema.rb index b8aecba..fd08ec2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140921225115) do +ActiveRecord::Schema.define(version: 20140922233036) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -60,15 +60,16 @@ ActiveRecord::Schema.define(version: 20140921225115) do t.integer "weight" t.boolean "helmet" t.boolean "lock" - t.string "agency" t.date "completion_date" t.datetime "created_at" t.datetime "updated_at" t.integer "bike_id" t.string "bike_type_requested" t.boolean "will_pay" + t.integer "agency_id" end + add_index "clients", ["agency_id"], name: "index_clients_on_agency_id", using: :btree add_index "clients", ["bike_id"], name: "index_clients_on_bike_id", using: :btree create_table "users", force: true do |t|