Browse Source

Louis | Adds page which shows freecyclery bikes that are ready for pickup

master
Loos 10 years ago
parent
commit
77e7109b9e
  1. 4
      app/controllers/bikes_controller.rb
  2. 13
      app/models/bike.rb
  3. 4
      app/models/client.rb
  4. 17
      app/views/bikes/freecyclery_pickup.html.haml
  5. 2
      app/views/static_pages/home.html.haml
  6. 1
      config/routes.rb

4
app/controllers/bikes_controller.rb

@ -38,6 +38,10 @@ class BikesController < ApplicationController
end
end
def freecyclery_pickup
@bikes_for_pickup = Bike.bikes_ready_for_pickup
end
def update
if @bike.update(bike_params)
redirect_to @bike, notice: 'Bike was successfully updated.'

13
app/models/bike.rb

@ -10,4 +10,17 @@ class Bike < ActiveRecord::Base
self.brand + ' ' + self.model
end
def client
client = Client.find_by bike_id: self.id
end
def ready_for_pickup?
client = self.client
client && self.completion_date && !client.application_voided
end
def self.bikes_ready_for_pickup
Bike.all.select{|bike| bike.ready_for_pickup?}
end
end

4
app/models/client.rb

@ -9,4 +9,8 @@ class Client < ActiveRecord::Base
waiting_list = incomplete_clients.sort_by!{|client| client.application_date}
end
def name
self.first_name + ' ' + self.last_name
end
end

17
app/views/bikes/freecyclery_pickup.html.haml

@ -0,0 +1,17 @@
.container
%br
%h1 Freecyclery Bikes for Pickup
%table.table.table-striped.table-bordered.table-hover
%thead
%tr
%th Brand
%th Model
%th Client
%tbody
- @bikes_for_pickup.each do |bike|
%tr
%td= bike.brand
%td= bike.model
%td= bike.client.name

2
app/views/static_pages/home.html.haml

@ -8,3 +8,5 @@
= link_to "Print Sale Bike Labels", print_select_bikes_path
%br
= link_to "Freecyclery Agencies", agencies_path
%br
= link_to "Freecyclery Bikes Ready for Pickup", freecyclery_pickup_bikes_path

1
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
get 'freecyclery_pickup' => 'bikes#freecyclery_pickup', on: :collection
patch 'mark_as_sold' => 'bikes#mark_as_sold', on: :member
end

Loading…
Cancel
Save