mirror of
				https://github.com/fspc/bike-database.git
				synced 2025-10-31 00:35:35 -04:00 
			
		
		
		
	lk | changes type of date stored for client pickup
This commit is contained in:
		
							parent
							
								
									3852c85432
								
							
						
					
					
						commit
						a8c8f4b3d8
					
				| @ -25,8 +25,7 @@ class ClientsController < ApplicationController | ||||
|   def update | ||||
|     @client.update(client_params) | ||||
|     if @client.save | ||||
|       notice = 'Client was successfully updated.' | ||||
|       redirect_to edit_client_url(@client), notice: "Client updated" | ||||
|       redirect_to edit_client_url(@client), notice: "Client was successfully updated" | ||||
|     else | ||||
|       render action: 'edit', notice: "Unable to update client" | ||||
|     end | ||||
| @ -38,7 +37,8 @@ class ClientsController < ApplicationController | ||||
|     end | ||||
| 
 | ||||
|     def client_params | ||||
|       params["client"]["application_date"] = Date.strptime(params["client"]["application_date"], '%m/%d/%Y') | ||||
|       params["client"]["application_date"] = Date.strptime(params["client"]["application_date"], '%m/%d/%Y') if params["client"]["application_date"] | ||||
|       params["client"]["pickup_date"] = Date.strptime(params["client"]["pickup_date"], '%m/%d/%Y') if params["client"]["pickup_date"] | ||||
|       params.require(:client).permit( | ||||
|         :first_name, | ||||
|         :last_name, | ||||
|  | ||||
| @ -91,7 +91,7 @@ | ||||
|   .form-group | ||||
|     = f.label "Bike Picked Up On:", class: "col-sm-2 control-label" | ||||
|     .col-sm-10 | ||||
|       = f.text_field :pickup_date, class: "form-control datepicker", disabled: disabled | ||||
|       = f.text_field :pickup_date, value: @client.pickup_date && @client.pickup_date.strftime('%m/%d/%Y'), class: "form-control datepicker", disabled: disabled | ||||
| 
 | ||||
|   .form-group | ||||
|     = f.label "Volunteer Present at Pickup:", class: "col-sm-2 control-label" | ||||
|  | ||||
							
								
								
									
										17
									
								
								db/migrate/20151230021120_change_pickup_date_to_date_time.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								db/migrate/20151230021120_change_pickup_date_to_date_time.rb
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,17 @@ | ||||
| class ChangePickupDateToDateTime < ActiveRecord::Migration | ||||
|   def up | ||||
|     add_column :clients, :pickup_datetime, :datetime | ||||
|     Client.all.to_a.each{ |client| | ||||
|       if client.pickup_date | ||||
|         client.update_attribute(:pickup_datetime, client.pickup_date) | ||||
|       end | ||||
|     } | ||||
|     rename_column :clients, :pickup_date, :pickup_date_bkp | ||||
|     rename_column :clients, :pickup_datetime, :pickup_date | ||||
|   end | ||||
| 
 | ||||
|   def down | ||||
|     remove_column :clients, :pickup_date | ||||
|     rename_column :clients, :pickup_date_bkp, :pickup_date | ||||
|   end | ||||
| end | ||||
| @ -11,7 +11,7 @@ | ||||
| # | ||||
| # It's strongly recommended that you check this file into your version control system. | ||||
| 
 | ||||
| ActiveRecord::Schema.define(version: 20151219225720) do | ||||
| ActiveRecord::Schema.define(version: 20151230021120) do | ||||
| 
 | ||||
|   # These are extensions that must be enabled in order to support this database | ||||
|   enable_extension "plpgsql" | ||||
| @ -66,11 +66,12 @@ ActiveRecord::Schema.define(version: 20151219225720) do | ||||
|     t.boolean  "bike_fixed" | ||||
|     t.integer  "number_of_calls" | ||||
|     t.boolean  "application_voided" | ||||
|     t.date     "pickup_date" | ||||
|     t.date     "pickup_date_bkp" | ||||
|     t.string   "volunteer_at_pickup" | ||||
|     t.float    "weight" | ||||
|     t.float    "height" | ||||
|     t.datetime "application_date" | ||||
|     t.datetime "pickup_date" | ||||
|   end | ||||
| 
 | ||||
|   add_index "clients", ["agency_id"], name: "index_clients_on_agency_id", using: :btree | ||||
|  | ||||
| @ -14,4 +14,11 @@ describe ClientsController do | ||||
|       expect(client.reload.application_date.strftime('%m/%d/%Y')).to eq("12/21/2015") | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   describe "PUT #update" do | ||||
|     it "updates a client with a pickup date" do | ||||
|       put :update, id: client.id, client: {pickup_date: "12/21/2015"} | ||||
|       expect(client.reload.pickup_date.strftime('%m/%d/%Y')).to eq("12/21/2015") | ||||
|     end | ||||
|   end | ||||
| end | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user