Browse Source

Louis | Adds form for selecting bike labels to print

master
Loos 10 years ago
parent
commit
49351e0f32
  1. 2
      app/controllers/application_controller.rb
  2. 13
      app/controllers/bikes_controller.rb
  3. 3
      app/views/bikes/print_labels.html.haml
  4. 14
      app/views/bikes/print_select.html.haml
  5. 2
      app/views/static_pages/home.html.haml
  6. 6
      config/routes.rb
  7. 4
      spec/routing/bikes_routing_spec.rb

2
app/controllers/application_controller.rb

@ -1,5 +1,3 @@
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception protect_from_forgery with: :exception
end end

13
app/controllers/bikes_controller.rb

@ -16,6 +16,15 @@ class BikesController < ApplicationController
def edit def edit
end end
def print_select
@bikes = Bike.all
end
def print_labels
bike_ids = print_params.map{|key, value| key if value == "1"}.compact
@bikes = Bike.find(bike_ids)
end
def create def create
@bike = Bike.new(bike_params) @bike = Bike.new(bike_params)
if @bike.save if @bike.save
@ -63,4 +72,8 @@ class BikesController < ApplicationController
:created_at, :created_at,
:updated_at) :updated_at)
end end
def print_params
params.require(:print_bikes)
end
end end

3
app/views/bikes/print_labels.html.haml

@ -0,0 +1,3 @@
- @bikes.each do |bike|
=bike.name
%br

14
app/views/bikes/print_select.html.haml

@ -0,0 +1,14 @@
.container
%h1 Select Bikes To Print
=form_tag("/bikes/print_labels", method: "get") do
%table.table.table-striped.table-bordered.table-hover
%thead
%tr
%th Bike
%th Select
-@bikes.each do |bike|
%tr
%td= bike.name
%td= check_box("print_bikes", bike.id)
=submit_tag 'Generate Labels', class: "btn btn-default"

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

@ -8,3 +8,5 @@
= link_to "Bikes", bikes_path = link_to "Bikes", bikes_path
%br %br
= link_to "Clients", clients_path = link_to "Clients", clients_path
%br
= link_to "Print Bikes", print_select_bikes_path

6
config/routes.rb

@ -2,7 +2,11 @@ Bikedb::Application.routes.draw do
devise_for :users devise_for :users
root to: "static_pages#home" root to: "static_pages#home"
resources :bikes resources :bikes do
get 'print_select' => 'bikes#print_select', on: :collection
get 'print_labels' => 'bikes#print_labels', on: :collection
end
resources :volunteers resources :volunteers
resources :clients resources :clients
end end

4
spec/routing/bikes_routing_spec.rb

@ -31,5 +31,9 @@ describe BikesController do
delete("/bikes/1").should route_to("bikes#destroy", :id => "1") delete("/bikes/1").should route_to("bikes#destroy", :id => "1")
end end
it "routes to #print_select" do
get("/bikes/print_select").should route_to("bikes#print_select")
end
end end
end end

Loading…
Cancel
Save