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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -