From cc00aec5adf150ed2c4829fdadaac1b0d54d9161 Mon Sep 17 00:00:00 2001 From: Louis Knapp Date: Sat, 30 Jul 2016 21:30:57 -0500 Subject: [PATCH] lk | renders date sold with consistent formatting --- app/controllers/bikes_controller.rb | 5 ++++- app/views/bikes/_fields.html.haml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/bikes_controller.rb b/app/controllers/bikes_controller.rb index 2f371cb..c05bd91 100644 --- a/app/controllers/bikes_controller.rb +++ b/app/controllers/bikes_controller.rb @@ -42,6 +42,8 @@ class BikesController < ApplicationController if @bike.save redirect_to new_bike_path, notice: 'Bike was successfully created.' else + @previous_bike = Bike.order(:log_number).last + @log_number = @bike.log_number render action: 'new' end end @@ -70,7 +72,8 @@ class BikesController < ApplicationController end def bike_params - params[:bike][:fixed_at] = DateTime.strptime(params[:bike][:fixed_at], "%m/%d/%Y") if params[:bike][:fixed_at] + params[:bike][:fixed_at] = DateTime.strptime(params[:bike][:fixed_at], "%m/%d/%Y") if params[:bike][:fixed_at].present? + params[:bike][:date_sold] = DateTime.strptime(params[:bike][:date_sold], "%m/%d/%Y") if params[:bike][:date_sold].present? params.require(:bike).permit( :fixed_at, :brand, diff --git a/app/views/bikes/_fields.html.haml b/app/views/bikes/_fields.html.haml index 1259eae..2a16b8f 100644 --- a/app/views/bikes/_fields.html.haml +++ b/app/views/bikes/_fields.html.haml @@ -86,5 +86,5 @@ .form-group = f.label "Date Sold:", class: "col-sm-4 control-label" .col-sm-6 - = f.text_field :date_sold, class: "form-control datepicker", disabled: disabled + = f.text_field :date_sold, :value => @bike.date_sold ? @bike.date_sold.strftime("%m/%d/%Y") : "", class: "form-control datepicker", disabled: disabled