mirror of
https://github.com/fspc/bike-database.git
synced 2025-04-04 10:03:22 -04:00
lk | changes way application date is stored in db
This commit is contained in:
parent
f694d8c238
commit
ef63d964d4
@ -23,14 +23,12 @@ class ClientsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if @client.update(client_params)
|
@client.update(client_params)
|
||||||
|
if @client.save
|
||||||
notice = 'Client was successfully updated.'
|
notice = 'Client was successfully updated.'
|
||||||
unless @client.bike.update_attribute(:date_sold, @client.pickup_date)
|
redirect_to edit_client_url(@client), notice: "Client updated"
|
||||||
notice = "Unable to update client's bike sale date"
|
|
||||||
end
|
|
||||||
redirect_to edit_client_url(@client), notice: notice
|
|
||||||
else
|
else
|
||||||
render action: 'edit'
|
render action: 'edit', notice: "Unable to update client"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -40,6 +38,7 @@ class ClientsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def client_params
|
def client_params
|
||||||
|
params["client"]["application_date"] = Date.strptime(params["client"]["application_date"], '%m/%d/%Y')
|
||||||
params.require(:client).permit(
|
params.require(:client).permit(
|
||||||
:first_name,
|
:first_name,
|
||||||
:last_name,
|
:last_name,
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
.form-group
|
.form-group
|
||||||
= f.label "Application Date:", class: "col-sm-2 control-label"
|
= f.label "Application Date:", class: "col-sm-2 control-label"
|
||||||
.col-sm-10
|
.col-sm-10
|
||||||
= f.text_field :application_date, class: "form-control datepicker", disabled: disabled
|
= f.text_field :application_date, value: @client.application_date && @client.application_date.strftime('%m/%d/%Y'), class: "form-control datepicker", disabled: disabled
|
||||||
|
|
||||||
.form-group
|
.form-group
|
||||||
= f.label "Agency:", class: "col-sm-2 control-label"
|
= f.label "Agency:", class: "col-sm-2 control-label"
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
# Date
|
# Date
|
||||||
Date::DATE_FORMATS[:default] = "%m/%d/%Y"
|
Date::DATE_FORMATS[:default] = "%m/%d/%Y"
|
||||||
|
Date::DATE_FORMATS[:db] = "%m/%d/%Y"
|
||||||
|
|
||||||
# Time
|
# Time
|
||||||
Time::DATE_FORMATS[:default] = "%m/%d/%Y"
|
Time::DATE_FORMATS[:default] = "%m/%d/%Y"
|
||||||
|
Date::DATE_FORMATS[:db] = "%m/%d/%Y"
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
class ChangeClientApplicationDateToString < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
add_column :clients, :application_datetime, :datetime
|
||||||
|
Client.all.to_a.each{ |client|
|
||||||
|
if client.application_date
|
||||||
|
client.update_attribute(:application_datetime, client.application_date)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
rename_column :clients, :application_date, :application_date_bkp
|
||||||
|
rename_column :clients, :application_datetime, :application_date
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
remove_column :clients, :application_date
|
||||||
|
rename_column :clients, :application_date_bkp, :application_date
|
||||||
|
end
|
||||||
|
end
|
@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20151205223152) do
|
ActiveRecord::Schema.define(version: 20151219225720) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@ -51,7 +51,7 @@ ActiveRecord::Schema.define(version: 20151205223152) do
|
|||||||
create_table "clients", force: :cascade do |t|
|
create_table "clients", force: :cascade do |t|
|
||||||
t.string "first_name"
|
t.string "first_name"
|
||||||
t.string "last_name"
|
t.string "last_name"
|
||||||
t.date "application_date"
|
t.date "application_date_bkp"
|
||||||
t.string "gender"
|
t.string "gender"
|
||||||
t.integer "age"
|
t.integer "age"
|
||||||
t.boolean "helmet"
|
t.boolean "helmet"
|
||||||
@ -70,6 +70,7 @@ ActiveRecord::Schema.define(version: 20151205223152) do
|
|||||||
t.string "volunteer_at_pickup"
|
t.string "volunteer_at_pickup"
|
||||||
t.float "weight"
|
t.float "weight"
|
||||||
t.float "height"
|
t.float "height"
|
||||||
|
t.datetime "application_date"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "clients", ["agency_id"], name: "index_clients_on_agency_id", using: :btree
|
add_index "clients", ["agency_id"], name: "index_clients_on_agency_id", using: :btree
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
on website, tailwind for tools initiative looks weird in carousel
|
||||||
|
on mobile
|
||||||
|
|
||||||
Freecyclery Receipts
|
Freecyclery Receipts
|
||||||
|
|
||||||
convert to bootstrap-less
|
convert to bootstrap-less
|
||||||
|
@ -28,6 +28,7 @@ describe BikesController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
describe "GET #new" do
|
describe "GET #new" do
|
||||||
it "assigns a log number" do
|
it "assigns a log number" do
|
||||||
FactoryGirl.create(:bike, log_number: 3)
|
FactoryGirl.create(:bike, log_number: 3)
|
||||||
|
17
spec/controllers/clients_controller_spec.rb
Normal file
17
spec/controllers/clients_controller_spec.rb
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe ClientsController do
|
||||||
|
let(:user){FactoryGirl.create(:user)}
|
||||||
|
let(:client){FactoryGirl.create(:client)}
|
||||||
|
|
||||||
|
before :each do
|
||||||
|
sign_in user
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "PUT #update" do
|
||||||
|
it "updates a client with an application date" do
|
||||||
|
put :update, id: client.id, client: {application_date: "12/21/2015"}
|
||||||
|
expect(client.reload.application_date.strftime('%m/%d/%Y')).to eq("12/21/2015")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user