diff --git a/app/controllers/bikes_controller.rb b/app/controllers/bikes_controller.rb index b8ca28a..1c75293 100644 --- a/app/controllers/bikes_controller.rb +++ b/app/controllers/bikes_controller.rb @@ -25,6 +25,16 @@ class BikesController < ApplicationController @bikes = Bike.find(bike_ids) end + def search + bike = Bike.where(log_number: params[:log_number]).first + if bike + redirect_to edit_bike_path(bike) + else + flash[:notice] = 'No bike with that log number was found' + redirect_to action: 'home', controller: 'static_pages' + end + end + def create @bike = Bike.new(bike_params) if @bike.save diff --git a/app/views/static_pages/home.html.haml b/app/views/static_pages/home.html.haml index cd0481d..f0275a4 100644 --- a/app/views/static_pages/home.html.haml +++ b/app/views/static_pages/home.html.haml @@ -2,6 +2,10 @@ %h1 Bike & Client Tracker %br %h2 Bikes + = form_tag("bikes/search", method: "get", class: "form-inline") do + = label_tag(:log_number, "Search by log number:") + = text_field_tag :log_number, "", class: "form-control" + = submit_tag("Search", class: "btn btn-default") %br = link_to "Log Bikes", new_bike_path %br diff --git a/config/routes.rb b/config/routes.rb index 1a7179f..c97c09a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,6 +7,7 @@ Bikedb::Application.routes.draw do mount Sidekiq::Web => '/sidekiq' resources :bikes do + get 'search' => 'bikes#search', on: :collection get 'print_select' => 'bikes#print_select', on: :collection get 'print_labels' => 'bikes#print_labels', on: :collection get 'freecyclery_pickup' => 'bikes#freecyclery_pickup', on: :collection