diff --git a/app/controllers/bikes_controller.rb b/app/controllers/bikes_controller.rb index d904911..c55ca4c 100644 --- a/app/controllers/bikes_controller.rb +++ b/app/controllers/bikes_controller.rb @@ -4,6 +4,10 @@ class BikesController < ApplicationController def index @bikes = Bike.all + @unsold_bikes = @bikes.select{|bike| + !bike.date_sold && + (bike.purpose == "Sale") + } end def show @@ -47,6 +51,17 @@ class BikesController < ApplicationController redirect_to bikes_url end + def mark_as_sold + current_date = Time.new.strftime("%Y-%m-%d") + @bike = Bike.find(params[:id]) + if @bike.update_attribute(:date_sold, current_date) + redirect_to bikes_url, notice: @bike.name + ' was marked as sold on ' + current_date + '.' + else + render action: edit, notice: 'Bike sale date could not be updated' + end + end + + private def set_bike @bike = Bike.find(params[:id]) diff --git a/app/views/bikes/edit.html.haml b/app/views/bikes/edit.html.haml index ad45be9..ad1bb60 100644 --- a/app/views/bikes/edit.html.haml +++ b/app/views/bikes/edit.html.haml @@ -1,5 +1,9 @@ .container - %h1 Editing bike + .row + .col-sm-6 + %h1 Edit bike + .col-sm-3.col-sm-offset-3 + =button_to "Mark as sold", {action: "mark_as_sold", id: @bike.id}, method: :patch, class: "btn btn-default" = render 'form' = link_to 'Show', @bike | diff --git a/app/views/bikes/index.html.haml b/app/views/bikes/index.html.haml index c7ca991..7fb8ecc 100644 --- a/app/views/bikes/index.html.haml +++ b/app/views/bikes/index.html.haml @@ -1,6 +1,9 @@ .container - %h1 Bikes + = link_to ' + Log Bike', new_bike_path, class: "btn btn-default" + %br + + %h1 Unsold Bikes %table.table.table-striped.table-bordered.table-hover %thead %tr @@ -8,6 +11,21 @@ %th Model %th %th + %tbody + - @unsold_bikes.each do |bike| + %tr + %td= bike.brand + %td= bike.model + %td= link_to 'Show', bike + %td= link_to 'Edit', edit_bike_path(bike) + + %h1 All Bikes + %table.table.table-striped.table-bordered.table-hover + %thead + %tr + %th Brand + %th Model + %th %th %tbody - @bikes.each do |bike| @@ -16,7 +34,4 @@ %td= bike.model %td= link_to 'Show', bike %td= link_to 'Edit', edit_bike_path(bike) - %td= link_to 'Destroy', bike, method: :delete, data: { confirm: 'Are you sure?' } - %br - = link_to ' + Log Bike', new_bike_path, class: "btn btn-default" diff --git a/app/views/bikes/print_labels.html.haml b/app/views/bikes/print_labels.html.haml index e7857e9..422ac3a 100644 --- a/app/views/bikes/print_labels.html.haml +++ b/app/views/bikes/print_labels.html.haml @@ -21,4 +21,4 @@ .strong New Parts: =bike.new_parts .row - .col-xs-6.col-xs-offset-6.small= "Log Number: " + bike.log_number.to_s + .col-xs-9.col-xs-offset-3.small= "Log Number: " + bike.log_number.to_s diff --git a/config/routes.rb b/config/routes.rb index 85f38cf..3db8192 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,7 @@ Bikedb::Application.routes.draw do resources :bikes do get 'print_select' => 'bikes#print_select', on: :collection get 'print_labels' => 'bikes#print_labels', on: :collection + patch 'mark_as_sold' => 'bikes#mark_as_sold', on: :member end resources :volunteers diff --git a/db/schema.rb b/db/schema.rb index 5598619..e51cd99 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,16 +1,3 @@ -# encoding: UTF-8 -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). -# -# It's strongly recommended that you check this file into your version control system. - ActiveRecord::Schema.define(version: 20140918211228) do # These are extensions that must be enabled in order to support this database