ruby on rails - How To Create Clothing Items Model - Different Sizes for Shoes, Shirts, Jeans ect -
im creating online retail store.
just wondering how of professionals go creating clothes model.
problem shoes have different sizes mens 8,9,10,12 ect. shirts have 38,40,42 chest. jeans have 32, 34,36. dresses have size 6, 8 ect.
how go making clothing items model. when creates , item, first click on category want. lets shoes, brings down list of shoe sizes , can put in quantity each shoe size have , other attributes price , ect.
you can use polymorphic associations solution looking for. case can create models shown below
# models class commonsize < activerecord::base belongs_to :common_sizable, :polymorphic => true end class shoe < activerecord::base has_many :common_sizes, :as => :common_sizable end class dress < activerecord::base has_many :common_sizes, :as => :common_sizable end class shirt < activerecord::base has_many :common_sizes, :as => :common_sizable end # controllers # shoes_controller def create shoe = shoe.new(...) shoe.common_size.build(...) shoe.save end # create other controllers
for understanding polymorphic associations in rails, can see video http://railscasts.com/episodes/154-polymorphic-association
Comments
Post a Comment