Problems like this are exactly why people use programming languages to “program” software.

This is no different than the book examples you have read – you just want to also have the concept of stock levels.

This is applicable to the book world as well. Amazon’s book selling system is aware of its stock levels. Powell’s is aware of its stock levels. However, unless they are really cool, the Paperback Book Exchange store down the street doesn’t.

What do you do?

Create a StockLevel model, that will “belong to” your Product class (in the case of the book store it might just be a Book class… if the types of products you are going to offer are all going to be different “models” then you’ll probably want to use polymorphic associations for your stock levels instead of a simple association).

Make a controller for your vendor to add stock to the product ( each row of stock level would have a float column with positive or negative allocations of stock made. )

When someone purchases one or more products, add an instance to your StockLevel model with the number the customer bought as a negative.

In your store logic, you can choose to show or not show your Products based on their availability.

This is one way to solve the problem with or without Rails. Rails though will certainly make this dead simple with very clean and readable code. You’ll find yourself building methods like Product#add_stock(5), Product#subtract_stock(1), Product#current_stock_level (which would just do a simple product.stock_levels.calculate(:sum, :level) ), etc.

Hope this helps you conceptualize what you’ve got in front of you.

D. Taylor Singletary,
Reality Technician