diff --git a/app/components/bikes.rb b/app/components/bikes.rb index 5de3e05..6b2f864 100644 --- a/app/components/bikes.rb +++ b/app/components/bikes.rb @@ -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"}, diff --git a/app/components/bikes/javascripts/init_component.js b/app/components/bikes/javascripts/init_component.js index 2171057..4561335 100644 --- a/app/components/bikes/javascripts/init_component.js +++ b/app/components/bikes/javascripts/init_component.js @@ -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"] diff --git a/app/models/bike.rb b/app/models/bike.rb index ffdc126..aced28e 100644 --- a/app/models/bike.rb +++ b/app/models/bike.rb @@ -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 diff --git a/app/models/bike_model.rb b/app/models/bike_model.rb index df3c410..8bd626d 100644 --- a/app/models/bike_model.rb +++ b/app/models/bike_model.rb @@ -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') diff --git a/db/migrate/20130902201853_add_model_to_bike.rb b/db/migrate/20130902201853_add_model_to_bike.rb new file mode 100644 index 0000000..f4d1a92 --- /dev/null +++ b/db/migrate/20130902201853_add_model_to_bike.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index cb1b3c9..3834603 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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