mirror of
https://github.com/fspc/bike-database.git
synced 2026-09-16 08:31:39 -04:00
Louis | user can mark bikes as picked up from the available freecyclery bikes page
This commit is contained in:
@@ -61,6 +61,12 @@ class BikesController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def mark_picked_up
|
||||
@bike = Bike.find(params[:id])
|
||||
@bike.mark_picked_up
|
||||
flash[:notice] = @bike.name + ' was marked as picked up'
|
||||
redirect_to action: "ready_for_pickup", controller: "freecyclery"
|
||||
end
|
||||
|
||||
private
|
||||
def set_bike
|
||||
|
||||
+6
-1
@@ -16,7 +16,7 @@ class Bike < ActiveRecord::Base
|
||||
|
||||
def ready_for_pickup?
|
||||
client = self.client
|
||||
client && self.completion_date && !client.application_voided
|
||||
client && self.completion_date && !client.application_voided && self.date_sold.nil?
|
||||
end
|
||||
|
||||
def self.bikes_ready_for_pickup
|
||||
@@ -27,4 +27,9 @@ class Bike < ActiveRecord::Base
|
||||
Bike.all.select{|bike| bike.completion_date && (bike.purpose == "Freecyclery") && !bike.client }
|
||||
end
|
||||
|
||||
def mark_picked_up
|
||||
current_date = Time.new.strftime("%Y-%m-%d")
|
||||
self.update_attribute(:date_sold, current_date)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -8,10 +8,12 @@
|
||||
%th Brand
|
||||
%th Model
|
||||
%th Client
|
||||
%th
|
||||
%tbody
|
||||
- @bikes_for_pickup.each do |bike|
|
||||
%tr
|
||||
%td= bike.brand
|
||||
%td= bike.model
|
||||
%td= bike.client.name
|
||||
%td= button_to "Mark as picked up", {controller: "bikes", action: "mark_picked_up", id: bike.id}, method: :patch, class: "btn btn-default"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user