I have a question about inheritance in Rails.
Say you have 3 tables:
Each table has different attributes, but they do share some of the same attributes respectively in each table:
Common attributes amongst all the tables:
- is_striped (say this is a boolean value)
Now say someone is browsing through your online clothing store buying socks, shirts and pants and they’re having a great time. When displaying all items in their cart, each line item is of a different product type technically, but yet they all share a few of the same attributes (material_used, color, manufacture).
Would it be wise to create a general Product class that stores the common attributes which is used for the initial @user.products query (assuming you have a valid User object and the superclass Product exists), and then each product type would inherit from Product.
class Product;end # initialize common attributes somehow
class Pants < Product;end # specify specific attributes
class Shirts < Product;end # specify specific attributes
class Socks < Product;end # specify specific attributes
I guess I’m a little confused on the best way to keep it simple (as well as how to create the Product class, which I think is a proxy class hooked up to ActiveRecord somehow… ?) when iterating through the clothes to see what kind of attributes they have and then display the proper info. I’d like to keep as much business logic out of the view as possible. Obviously Pants don’t have an attribute called “foot_size”. I don’t have the option of changing the database tables too much, so STI is a no-go for this project. I’m thinking more of going the class table inheritance route, but I’m not sure. (
Are there any tutorials that cover what I’m talking about? If it matters, I’m stuck with Oracle. Did any of this make sense or am I on crazy pills?