Rails 3 Abstract Class vs Inherited Class?

I'd use neither, and follow what Mörre suggested to have InventoryItem be a join model.

I'd use neither, and follow what Mörre suggested to have InventoryItem be a join model: class Store has_many :inventory_items has_many :products, :services, :through => :inventory_items end class InventoryItem belongs_to :store belongs_to :products, :services end class Product has_many :inventory_items has_many :stores, :through => :inventory_items end class Service has_many :inventory_items has_many :stores, :through => :inventory_items end.

Yes, sorry, my terminology was a bit obtuse, I'm trying to create a view which allows my user to add items to their store through a singular field. So say a combobox that has all the items (both products and services), and so I was trying to figure out how to model that. It sounds like this association will do what I need.

– R. Yanchuleff Mar 2 at 15:53 If I understand this correctly, I'll be able to do storeObj. Inventory_items.

Count and get the total number of products and services in the store because of the join model? Or more importantly, I can print say an invoice of all products and services by doing something like print_invoice_store_path(@inventory_items)? – R.

Yanchuleff Mar 2 at 15:54 regarding store. Inventory_items. Count, yeah, as with any has_many association.Re print_invoice_store_path, that might be worth asking separately, but in principle yes as well.

I'd imagine it more like print_invoice_store_path(@store) though, and then you could access @store. Inventory_items within the action.In any case, the associated collection will be available for you to process or output anyway you like – Oliver Barnes Mar 2 at 21:01 re the combobox intention, yes this should work for it. I didn't find the question obtuse :) Having a clear picture of an interface and what you're trying to accomplish does help a lot though.

– Oliver Barnes Mar 2 at 21:07.

Personally, I would not use inheritance. Why don't you just say has_many :services has_many :products Inheritance is pretty expensive - both in terms of runtime and often in readability too. This case sounds like a very basic case for which no inheritance is required.Do you really want products and services to actually INHERIT something from a base class?

What you writes indicates all you want is to establish the association.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions