Browse Source

lk | add ability to search by bike log #

master
Louis Knapp 9 years ago
parent
commit
bc3b5f8a1a
  1. 10
      app/controllers/bikes_controller.rb
  2. 4
      app/views/static_pages/home.html.haml
  3. 1
      config/routes.rb

10
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

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

@ -2,6 +2,10 @@
%h1 Bike &amp; 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

1
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

Loading…
Cancel
Save