Browse Source

Merge pull request #61 from spacemunkay/denney-move-model-to-bike

Moving bike model to the bikes table
eperez-timeinput
Jason Denney 11 years ago
parent
commit
8c6513099d
  1. 4
      app/components/bikes.rb
  2. 1
      app/components/bikes/javascripts/init_component.js
  3. 9
      app/models/bike.rb
  4. 1
      app/models/bike_model.rb
  5. 10
      db/migrate/20130902201853_add_model_to_bike.rb
  6. 5
      db/schema.rb

4
app/components/bikes.rb

@ -10,7 +10,7 @@ class Bikes < Netzke::Basepack::Grid
{ :name => :shop_id, :text => 'Shop ID'}, { :name => :shop_id, :text => 'Shop ID'},
:serial_number, :serial_number,
{ :id => :bike_brand__brand, :name => :bike_brand__brand, :text => 'Brand'}, { :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| :scope => lambda { |rel|
if session[:selected_bike_brand_id] if session[:selected_bike_brand_id]
rel.where(:bike_brand_id => 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 # :field_label MUST be defined in order for search to work
[ [
{ :name => :bike_brand__brand, :field_label => 'Brand' }, { :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 => :shop_id, :field_label => 'Shop ID'},
{ :name => :serial_number, :field_label => 'Serial Number'}, { :name => :serial_number, :field_label => 'Serial Number'},
{ :name => "color", :xtype => "xcolorcombo"}, { :name => "color", :xtype => "xcolorcombo"},

1
app/components/bikes/javascripts/init_component.js

@ -6,7 +6,6 @@
//due to Netzke bug, :min_chars attribute doesn't work //due to Netzke bug, :min_chars attribute doesn't work
var min_char_columns = [ var min_char_columns = [
"bike_brand__brand", "bike_brand__brand",
"bike_model__model",
"bike_style__style", "bike_style__style",
"bike_condition__condition", "bike_condition__condition",
"bike_purpose__purpose"] "bike_purpose__purpose"]

9
app/models/bike.rb

@ -1,6 +1,6 @@
class Bike < ActiveRecord::Base class Bike < ActiveRecord::Base
acts_as_loggable 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 :top_tube_length, :wheel_size, :value, :bike_condition_id, :bike_purpose_id
has_many :transactions has_many :transactions
@ -8,15 +8,14 @@ class Bike < ActiveRecord::Base
has_one :owner, :class_name => 'User' has_one :owner, :class_name => 'User'
has_one :task_list, :as => :item, :dependent => :destroy has_one :task_list, :as => :item, :dependent => :destroy
belongs_to :bike_brand belongs_to :bike_brand
belongs_to :bike_model
belongs_to :bike_style belongs_to :bike_style
belongs_to :bike_condition belongs_to :bike_condition
belongs_to :bike_purpose belongs_to :bike_purpose
validates :shop_id, :presence => true, :uniqueness => true, :length => { :minimum => 3 } validates :shop_id, :presence => true, :uniqueness => true, :length => { :minimum => 3 }
validates :serial_number, :length => { :minimum => 3 } validates :serial_number, :length => { :minimum => 3 }
validates :model, :length => { :maximum => 50 }
validates :bike_brand_id, :presence => true validates :bike_brand_id, :presence => true
validates :bike_model_id, :presence => true
validates :color, :presence => true validates :color, :presence => true
validates :bike_style_id, :presence => true validates :bike_style_id, :presence => true
validates :seat_tube_height, :presence => true validates :seat_tube_height, :presence => true
@ -34,10 +33,6 @@ class Bike < ActiveRecord::Base
self.bike_brand self.bike_brand
end end
def model
self.bike_model
end
def style def style
self.bike_style self.bike_style
end end

1
app/models/bike_model.rb

@ -1,7 +1,6 @@
class BikeModel < ActiveRecord::Base class BikeModel < ActiveRecord::Base
attr_accessible :model, :bike_brand_id attr_accessible :model, :bike_brand_id
has_many :bikes
belongs_to :bike_brand belongs_to :bike_brand
default_scope order('model ASC') default_scope order('model ASC')

10
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

5
db/schema.rb

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # 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| create_table "bike_actions", :force => true do |t|
t.string "action", :limit => 128, :null => false t.string "action", :limit => 128, :null => false
@ -49,7 +49,7 @@ ActiveRecord::Schema.define(:version => 20130902164600) do
create_table "bikes", :force => true do |t| create_table "bikes", :force => true do |t|
t.string "serial_number" t.string "serial_number"
t.integer "bike_brand_id", :null => false t.integer "bike_brand_id", :null => false
t.integer "bike_model_id", :null => false t.integer "bike_model_id"
t.string "color" t.string "color"
t.integer "bike_style_id", :null => false t.integer "bike_style_id", :null => false
t.float "seat_tube_height" t.float "seat_tube_height"
@ -61,6 +61,7 @@ ActiveRecord::Schema.define(:version => 20130902164600) do
t.datetime "created_at", :null => false t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
t.string "shop_id" t.string "shop_id"
t.string "model"
end end
add_index "bikes", ["shop_id"], :name => "index_bikes_on_shop_id", :unique => true add_index "bikes", ["shop_id"], :name => "index_bikes_on_shop_id", :unique => true

Loading…
Cancel
Save