mirror of
				https://github.com/fspc/bike-database.git
				synced 2025-10-31 16:45:34 -04:00 
			
		
		
		
	Louis | Adds form for selecting bike labels to print
This commit is contained in:
		
							parent
							
								
									0c581e775f
								
							
						
					
					
						commit
						49351e0f32
					
				| @ -1,5 +1,3 @@ | ||||
| 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 | ||||
| end | ||||
|  | ||||
| @ -16,6 +16,15 @@ class BikesController < ApplicationController | ||||
|   def edit | ||||
|   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 | ||||
|     @bike = Bike.new(bike_params) | ||||
|     if @bike.save | ||||
| @ -63,4 +72,8 @@ class BikesController < ApplicationController | ||||
|         :created_at,  | ||||
|         :updated_at)  | ||||
|     end | ||||
| 
 | ||||
|     def print_params | ||||
|       params.require(:print_bikes) | ||||
|     end | ||||
| end | ||||
|  | ||||
							
								
								
									
										3
									
								
								app/views/bikes/print_labels.html.haml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								app/views/bikes/print_labels.html.haml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | ||||
| - @bikes.each do |bike| | ||||
|   =bike.name | ||||
|   %br | ||||
							
								
								
									
										14
									
								
								app/views/bikes/print_select.html.haml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								app/views/bikes/print_select.html.haml
									
									
									
									
									
										Normal file
									
								
							| @ -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"  | ||||
| @ -8,3 +8,5 @@ | ||||
|   = link_to "Bikes", bikes_path | ||||
|   %br | ||||
|   = link_to "Clients", clients_path | ||||
|   %br | ||||
|   = link_to "Print Bikes", print_select_bikes_path | ||||
|  | ||||
| @ -2,7 +2,11 @@ Bikedb::Application.routes.draw do | ||||
|   devise_for :users | ||||
|   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 :clients | ||||
| end | ||||
|  | ||||
| @ -31,5 +31,9 @@ describe BikesController do | ||||
|       delete("/bikes/1").should route_to("bikes#destroy", :id => "1") | ||||
|     end | ||||
| 
 | ||||
|     it "routes to #print_select" do | ||||
|       get("/bikes/print_select").should route_to("bikes#print_select") | ||||
|     end | ||||
| 
 | ||||
|   end | ||||
| end | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user