Rails way for multi product types shopping cart
activerecord, ruby-on-rails, ruby-on-rails-3.2
Solution
The Dynamic Attributes gem should allow you to do this automatically:
https://github.com/moiristo/dynamic_attributes
There may be better gems that do what you need, but this is the first I found.
If you're using Postgres as your database, then you can use hstore. There are gems to work with hstore. If you can afford, get a subscription to railscast and watch the screencast about implementing hstore.
Activerecord-postgres-hstore seems to be the go to gem for this.
Problem
Im designing an application which manages the renting of lots of different equipment. And I am wondering whats the best way to design the models for the application. My software has to manage lots of different types of equipment (with data types) for example: ``` Speaker Make - String Model - String Wattage - Integer Price - Decimal Light Make - String Model - String Wattage - Integer Price - Decimal Microphone Make - String Model - String Use - Choice of: Instrumental, Vocal, Versatile Price - Decimal Cable Length - Decimal Connector 1 - String Connector 2 - String Price - Decimal Stand Type - Choice of: Microphone, Speaker Height - Decimal Boom - Boolean Price - Decimal ``` Ways I have thought about the design: - An individual model for each type of product then a polymorphic association in the cart so that it can handle all the types of equipment. - A single product model that has fields for all types of equipment with a type field which can be checked when ever the product is used. - A product model with a price attribute then every type of product extends that model. But what is the best way in rails to handle these different types of products?