mirror of
				https://github.com/fspc/BikeShed-1.git
				synced 2025-10-31 00:45:35 -04:00 
			
		
		
		
	Merge pull request #61 from spacemunkay/denney-move-model-to-bike
Moving bike model to the bikes table
This commit is contained in:
		
						commit
						8c6513099d
					
				| @ -10,7 +10,7 @@ class Bikes < Netzke::Basepack::Grid | ||||
|       { :name => :shop_id, :text => 'Shop ID'}, | ||||
|       :serial_number, | ||||
|       { :id => :bike_brand__brand, :name => :bike_brand__brand, :text => 'Brand'}, | ||||
|       { :id => :bike_model__model, :name => :bike_model__model, :text => 'Model', | ||||
|       { :name => :model, :text => 'Model', | ||||
|         :scope => lambda { |rel| | ||||
|                     if session[:selected_bike_brand_id] | ||||
|                       rel.where(:bike_brand_id => session[:selected_bike_brand_id]) | ||||
| @ -43,7 +43,7 @@ class Bikes < Netzke::Basepack::Grid | ||||
|     # :field_label MUST be defined in order for search to work | ||||
|     [ | ||||
|       { :name => :bike_brand__brand, :field_label => 'Brand' }, | ||||
|       { :name => :bike_model__model, :field_label => 'Model'}, | ||||
|       { :name => :model, :field_label => 'Model'}, | ||||
|       { :name => :shop_id, :field_label => 'Shop ID'}, | ||||
|       { :name => :serial_number, :field_label => 'Serial Number'}, | ||||
|       { :name => "color", :xtype => "xcolorcombo"}, | ||||
|  | ||||
| @ -6,7 +6,6 @@ | ||||
|     //due to Netzke bug, :min_chars attribute doesn't work
 | ||||
|     var min_char_columns = [ | ||||
|       "bike_brand__brand", | ||||
|       "bike_model__model", | ||||
|       "bike_style__style", | ||||
|       "bike_condition__condition", | ||||
|       "bike_purpose__purpose"] | ||||
|  | ||||
| @ -1,6 +1,6 @@ | ||||
| class Bike < ActiveRecord::Base | ||||
|   acts_as_loggable | ||||
|   attr_accessible :shop_id, :serial_number, :bike_brand_id, :bike_model_id, :color, :bike_style_id, :seat_tube_height, | ||||
|   attr_accessible :shop_id, :serial_number, :bike_brand_id, :model, :color, :bike_style_id, :seat_tube_height, | ||||
|     :top_tube_length, :wheel_size, :value, :bike_condition_id, :bike_purpose_id | ||||
| 
 | ||||
|   has_many :transactions | ||||
| @ -8,15 +8,14 @@ class Bike < ActiveRecord::Base | ||||
|   has_one :owner, :class_name => 'User' | ||||
|   has_one :task_list, :as => :item, :dependent => :destroy | ||||
|   belongs_to :bike_brand | ||||
|   belongs_to :bike_model | ||||
|   belongs_to :bike_style | ||||
|   belongs_to :bike_condition | ||||
|   belongs_to :bike_purpose | ||||
| 
 | ||||
|   validates :shop_id, :presence => true, :uniqueness => true, :length => { :minimum => 3 } | ||||
|   validates :serial_number, :length => { :minimum => 3 } | ||||
|   validates :model, :length => { :maximum => 50 } | ||||
|   validates :bike_brand_id, :presence => true | ||||
|   validates :bike_model_id, :presence => true | ||||
|   validates :color, :presence => true | ||||
|   validates :bike_style_id, :presence => true | ||||
|   validates :seat_tube_height, :presence => true | ||||
| @ -34,10 +33,6 @@ class Bike < ActiveRecord::Base | ||||
|     self.bike_brand | ||||
|   end | ||||
| 
 | ||||
|   def model | ||||
|     self.bike_model | ||||
|   end | ||||
| 
 | ||||
|   def style | ||||
|     self.bike_style | ||||
|   end | ||||
|  | ||||
| @ -1,7 +1,6 @@ | ||||
| class BikeModel < ActiveRecord::Base | ||||
|   attr_accessible :model, :bike_brand_id | ||||
| 
 | ||||
|   has_many :bikes | ||||
|   belongs_to :bike_brand | ||||
| 
 | ||||
|   default_scope order('model ASC') | ||||
|  | ||||
							
								
								
									
										10
									
								
								db/migrate/20130902201853_add_model_to_bike.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								db/migrate/20130902201853_add_model_to_bike.rb
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,10 @@ | ||||
| class AddModelToBike < ActiveRecord::Migration | ||||
|   def change | ||||
|     add_column :bikes, :model, :string | ||||
|     change_column :bikes, :bike_model_id, :integer, :null => true | ||||
|     Bike.all.each do |bike| | ||||
|       bike.model = BikeModel.find_by_id(bike.bike_model_id).model | ||||
|       bike.save | ||||
|     end | ||||
|   end | ||||
| end | ||||
| @ -11,7 +11,7 @@ | ||||
| # | ||||
| # It's strongly recommended to check this file into your version control system. | ||||
| 
 | ||||
| ActiveRecord::Schema.define(:version => 20130902164600) do | ||||
| ActiveRecord::Schema.define(:version => 20130902201853) do | ||||
| 
 | ||||
|   create_table "bike_actions", :force => true do |t| | ||||
|     t.string   "action",     :limit => 128, :null => false | ||||
| @ -49,7 +49,7 @@ ActiveRecord::Schema.define(:version => 20130902164600) do | ||||
|   create_table "bikes", :force => true do |t| | ||||
|     t.string   "serial_number" | ||||
|     t.integer  "bike_brand_id",     :null => false | ||||
|     t.integer  "bike_model_id",     :null => false | ||||
|     t.integer  "bike_model_id" | ||||
|     t.string   "color" | ||||
|     t.integer  "bike_style_id",     :null => false | ||||
|     t.float    "seat_tube_height" | ||||
| @ -61,6 +61,7 @@ ActiveRecord::Schema.define(:version => 20130902164600) do | ||||
|     t.datetime "created_at",        :null => false | ||||
|     t.datetime "updated_at",        :null => false | ||||
|     t.string   "shop_id" | ||||
|     t.string   "model" | ||||
|   end | ||||
| 
 | ||||
|   add_index "bikes", ["shop_id"], :name => "index_bikes_on_shop_id", :unique => true | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user