mirror of
				https://github.com/fspc/BikeShed-1.git
				synced 2025-10-31 00:45:35 -04:00 
			
		
		
		
	Add bike routes, controller, and views. Update model.
This commit is contained in:
		
							parent
							
								
									885caefaf7
								
							
						
					
					
						commit
						d3c466761e
					
				
							
								
								
									
										35
									
								
								app/controllers/bikes_controller.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								app/controllers/bikes_controller.rb
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,35 @@ | ||||
| class BikesController < AuthenticatedController | ||||
|   expose(:bike) | ||||
| 
 | ||||
|   expose(:bikes) { Bike.order('id').paginate(:page => params[:page]) } | ||||
| 
 | ||||
|   def index | ||||
|   end | ||||
| 
 | ||||
|   def show | ||||
|   end | ||||
| 
 | ||||
|   def new | ||||
|   end | ||||
| 
 | ||||
|   def create | ||||
|     if bike.save | ||||
|       redirect_to bike | ||||
|     else | ||||
|       render :new | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   def update | ||||
|     if bike.save | ||||
|       redirect_to bike | ||||
|     else | ||||
|       render :edit | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   def destroy | ||||
|     bike.destroy | ||||
|     redirect_to bikes_url | ||||
|   end | ||||
| end | ||||
| @ -3,11 +3,11 @@ class Bike < ActiveRecord::Base | ||||
|     :top_tube_length, :wheel_size, :value, :bike_condition_id, :bike_status_id | ||||
| 
 | ||||
|   has_one :owner, :class_name => 'User' | ||||
|   has_one :brand, :class_name => 'BikeBrand' | ||||
|   has_one :model, :class_name => 'BikeModel' | ||||
|   has_one :style, :class_name => 'BikeStyle' | ||||
|   has_one :condition, :class_name => 'BikeCondition' | ||||
|   has_one :status, :class_name => 'BikeStatus' | ||||
|   belongs_to :bike_brand | ||||
|   belongs_to :bike_model | ||||
|   belongs_to :bike_style | ||||
|   belongs_to :bike_condition | ||||
|   belongs_to :bike_status | ||||
| 
 | ||||
|   validates :serial_number, :uniqueness => true, :length => { :minimum => 3 } | ||||
|   validates :bike_brand_id, :presence => true | ||||
| @ -23,6 +23,26 @@ class Bike < ActiveRecord::Base | ||||
| 
 | ||||
|   self.per_page = 15 | ||||
| 
 | ||||
|   def brand | ||||
|     self.bike_brand | ||||
|   end | ||||
|    | ||||
|   def model | ||||
|     self.bike_model | ||||
|   end | ||||
| 
 | ||||
|   def style | ||||
|     self.bike_style | ||||
|   end | ||||
| 
 | ||||
|   def condition | ||||
|     self.bike_condition | ||||
|   end | ||||
| 
 | ||||
|   def status | ||||
|     self.bike_status | ||||
|   end | ||||
| 
 | ||||
|   def to_s | ||||
|     "#{brand} - #{model} - #{style}" | ||||
|   end | ||||
|  | ||||
							
								
								
									
										48
									
								
								app/views/bikes/_form.html.haml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								app/views/bikes/_form.html.haml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,48 @@ | ||||
| = form_for bike, :html => { :class => 'form-horizontal' } do |f| | ||||
|   .control-group | ||||
|     = f.label :serial_number, :class => 'control-label' | ||||
|     .controls | ||||
|       = f.text_field :serial_number, :class => 'text_field' | ||||
|   .control-group | ||||
|     = f.label :bike_brand_id, :class => 'control-label' | ||||
|     .controls | ||||
|       = f.number_field :bike_brand_id, :class => 'number_field' | ||||
|   .control-group | ||||
|     = f.label :bike_model_id, :class => 'control-label' | ||||
|     .controls | ||||
|       = f.number_field :bike_model_id, :class => 'number_field' | ||||
|   .control-group | ||||
|     = f.label :color, :class => 'control-label' | ||||
|     .controls | ||||
|       = f.text_field :color, :class => 'text_field' | ||||
|   .control-group | ||||
|     = f.label :bike_style_id, :class => 'control-label' | ||||
|     .controls | ||||
|       = f.number_field :bike_style_id, :class => 'number_field' | ||||
|   .control-group | ||||
|     = f.label :seat_tube_height, :class => 'control-label' | ||||
|     .controls | ||||
|       = f.text_field :seat_tube_height, :class => 'text_field' | ||||
|   .control-group | ||||
|     = f.label :top_tube_length, :class => 'control-label' | ||||
|     .controls | ||||
|       = f.text_field :top_tube_length, :class => 'text_field' | ||||
|   .control-group | ||||
|     = f.label :wheel_size, :class => 'control-label' | ||||
|     .controls | ||||
|       = f.number_field :wheel_size, :class => 'number_field' | ||||
|   .control-group | ||||
|     = f.label :value, :class => 'control-label' | ||||
|     .controls | ||||
|       = f.text_field :value, :class => 'text_field' | ||||
|   .control-group | ||||
|     = f.label :bike_condition_id, :class => 'control-label' | ||||
|     .controls | ||||
|       = f.text_field :bike_condition_id, :class => 'text_field' | ||||
|   .control-group | ||||
|     = f.label :bike_status_id, :class => 'control-label' | ||||
|     .controls | ||||
|       = f.number_field :bike_status_id, :class => 'number_field' | ||||
|   .form-actions | ||||
|     = f.submit nil, :class => 'btn btn-primary' | ||||
|     = link_to t('.cancel', :default => t("helpers.links.cancel")), bikes_path, :class => 'btn' | ||||
							
								
								
									
										4
									
								
								app/views/bikes/edit.html.haml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								app/views/bikes/edit.html.haml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | ||||
| - model_class = bike.class | ||||
| .page-header | ||||
|   %h1=t '.title', :default => t('helpers.titles.edit', :model => model_class.model_name.human, :default => "Edit #{model_class.model_name.human}") | ||||
| = render :partial => "form" | ||||
							
								
								
									
										41
									
								
								app/views/bikes/index.html.haml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								app/views/bikes/index.html.haml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,41 @@ | ||||
| - model_class = Bike.new.class | ||||
| .page-header | ||||
|   %h1=t '.title', :default => model_class.model_name.human.pluralize | ||||
| %table.table.table-striped | ||||
|   %thead | ||||
|     %tr | ||||
|       %th= model_class.human_attribute_name(:id) | ||||
|       %th= model_class.human_attribute_name(:serial_number) | ||||
|       %th= model_class.human_attribute_name(:bike_brand_id) | ||||
|       %th= model_class.human_attribute_name(:bike_model_id) | ||||
|       %th= model_class.human_attribute_name(:color) | ||||
|       %th= model_class.human_attribute_name(:bike_style_id) | ||||
|       %th= model_class.human_attribute_name(:seat_tube_height) | ||||
|       %th= model_class.human_attribute_name(:top_tube_length) | ||||
|       %th= model_class.human_attribute_name(:wheel_size) | ||||
|       %th= model_class.human_attribute_name(:value) | ||||
|       %th= model_class.human_attribute_name(:bike_condition_id) | ||||
|       %th= model_class.human_attribute_name(:bike_status_id) | ||||
|       %th= model_class.human_attribute_name(:created_at) | ||||
|       %th=t '.actions', :default => t("helpers.actions") | ||||
|   %tbody | ||||
|     - bikes.each do |bike| | ||||
|       %tr | ||||
|         %td= link_to bike.id, bike_path(bike) | ||||
|         %td= link_to bike.serial_number, bike_path(bike) | ||||
|         %td= bike.brand | ||||
|         %td= bike.model | ||||
|         %td= bike.color | ||||
|         %td= bike.style | ||||
|         %td= bike.seat_tube_height | ||||
|         %td= bike.top_tube_length | ||||
|         %td= bike.wheel_size | ||||
|         %td= bike.value | ||||
|         %td= bike.condition | ||||
|         %td= bike.status | ||||
|         %td= bike.created_at | ||||
|         %td | ||||
|           = link_to t('.edit', :default => t("helpers.links.edit")), edit_bike_path(bike), :class => 'btn btn-mini' | ||||
|           = link_to t('.destroy', :default => t("helpers.links.destroy")), bike_path(bike), :method => :delete, :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')), :class => 'btn btn-mini btn-danger' | ||||
| = will_paginate bikes | ||||
| = link_to t('.new', :default => t("helpers.links.new")), new_bike_path, :class => 'btn btn-primary' | ||||
							
								
								
									
										4
									
								
								app/views/bikes/new.html.haml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								app/views/bikes/new.html.haml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | ||||
| - model_class = bike.class | ||||
| .page-header | ||||
|   %h1=t '.title', :default => t('helpers.titles.new', :model => model_class.model_name.human, :default => "New #{model_class.model_name.human}") | ||||
| = render :partial => "form" | ||||
							
								
								
									
										53
									
								
								app/views/bikes/show.html.haml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								app/views/bikes/show.html.haml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,53 @@ | ||||
| - model_class = bike.class | ||||
| .page-header | ||||
|   %h1=t '.title', :default => model_class.model_name.human | ||||
| 
 | ||||
| %p | ||||
|   %strong= model_class.human_attribute_name(:serial_number) + ':' | ||||
|   %br | ||||
|   = bike.serial_number | ||||
| %p | ||||
|   %strong= model_class.human_attribute_name(:bike_brand_id) + ':' | ||||
|   %br | ||||
|   = bike.brand | ||||
| %p | ||||
|   %strong= model_class.human_attribute_name(:bike_model_id) + ':' | ||||
|   %br | ||||
|   = bike.model | ||||
| %p | ||||
|   %strong= model_class.human_attribute_name(:color) + ':' | ||||
|   %br | ||||
|   = bike.color | ||||
| %p | ||||
|   %strong= model_class.human_attribute_name(:bike_style_id) + ':' | ||||
|   %br | ||||
|   = bike.style | ||||
| %p | ||||
|   %strong= model_class.human_attribute_name(:seat_tube_height) + ':' | ||||
|   %br | ||||
|   = bike.seat_tube_height | ||||
| %p | ||||
|   %strong= model_class.human_attribute_name(:top_tube_length) + ':' | ||||
|   %br | ||||
|   = bike.top_tube_length | ||||
| %p | ||||
|   %strong= model_class.human_attribute_name(:wheel_size) + ':' | ||||
|   %br | ||||
|   = bike.wheel_size | ||||
| %p | ||||
|   %strong= model_class.human_attribute_name(:value) + ':' | ||||
|   %br | ||||
|   = bike.value | ||||
| %p | ||||
|   %strong= model_class.human_attribute_name(:bike_condition_id) + ':' | ||||
|   %br | ||||
|   = bike.condition | ||||
| %p | ||||
|   %strong= model_class.human_attribute_name(:bike_status_id) + ':' | ||||
|   %br | ||||
|   = bike.status | ||||
| 
 | ||||
| .form-actions | ||||
|   = link_to t('.back', :default => t("helpers.links.back")), bikes_path, :class => 'btn' | ||||
|   = link_to t('.edit', :default => t("helpers.links.edit")), edit_bike_path(bike), :class => 'btn' | ||||
|   = link_to t('.destroy', :default => t("helpers.links.destroy")), bike_path(bike), :method => "delete", :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')), :class => 'btn btn-danger' | ||||
| @ -11,6 +11,7 @@ Velocipede::Application.routes.draw do | ||||
|   resources :bike_models, :except => [:edit, :delete] | ||||
|   resources :bike_statuses | ||||
|   resources :bike_styles | ||||
|   resources :bikes | ||||
| 
 | ||||
|   #resources :clues | ||||
|   #resources :maps | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user