mirror of
https://github.com/fspc/bike-database.git
synced 2025-02-23 01:23:24 -05:00
Louis | Adding mark-as-sold button to bike edit page
This commit is contained in:
parent
1b6255a20c
commit
b8fc1eff42
@ -4,6 +4,10 @@ class BikesController < ApplicationController
|
|||||||
|
|
||||||
def index
|
def index
|
||||||
@bikes = Bike.all
|
@bikes = Bike.all
|
||||||
|
@unsold_bikes = @bikes.select{|bike|
|
||||||
|
!bike.date_sold &&
|
||||||
|
(bike.purpose == "Sale")
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@ -47,6 +51,17 @@ class BikesController < ApplicationController
|
|||||||
redirect_to bikes_url
|
redirect_to bikes_url
|
||||||
end
|
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
|
private
|
||||||
def set_bike
|
def set_bike
|
||||||
@bike = Bike.find(params[:id])
|
@bike = Bike.find(params[:id])
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
.container
|
.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'
|
= render 'form'
|
||||||
= link_to 'Show', @bike
|
= link_to 'Show', @bike
|
||||||
|
|
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
.container
|
.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
|
%table.table.table-striped.table-bordered.table-hover
|
||||||
%thead
|
%thead
|
||||||
%tr
|
%tr
|
||||||
@ -8,6 +11,21 @@
|
|||||||
%th Model
|
%th Model
|
||||||
%th
|
%th
|
||||||
%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
|
%th
|
||||||
%tbody
|
%tbody
|
||||||
- @bikes.each do |bike|
|
- @bikes.each do |bike|
|
||||||
@ -16,7 +34,4 @@
|
|||||||
%td= bike.model
|
%td= bike.model
|
||||||
%td= link_to 'Show', bike
|
%td= link_to 'Show', bike
|
||||||
%td= link_to 'Edit', edit_bike_path(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"
|
|
||||||
|
@ -21,4 +21,4 @@
|
|||||||
.strong New Parts:
|
.strong New Parts:
|
||||||
=bike.new_parts
|
=bike.new_parts
|
||||||
.row
|
.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
|
||||||
|
@ -5,6 +5,7 @@ Bikedb::Application.routes.draw do
|
|||||||
resources :bikes do
|
resources :bikes do
|
||||||
get 'print_select' => 'bikes#print_select', on: :collection
|
get 'print_select' => 'bikes#print_select', on: :collection
|
||||||
get 'print_labels' => 'bikes#print_labels', on: :collection
|
get 'print_labels' => 'bikes#print_labels', on: :collection
|
||||||
|
patch 'mark_as_sold' => 'bikes#mark_as_sold', on: :member
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :volunteers
|
resources :volunteers
|
||||||
|
13
db/schema.rb
13
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
|
ActiveRecord::Schema.define(version: 20140918211228) 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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user