Q:

Rails4 Sales Transaction History Table

I'm looking for a solution to record sales transactions.  Currently if I modify the price of a product, it will change the value of a previous sale because it is generated dynamically.  How do I create a history table so these transactions are stored?  Is there a gem for this?

A:

If you want the price to remain constant in the sales table you should copy the price over to a price column in the sales table. However, if this isn't what you want and you really need a history of versions on the products table use a versioning gem such as:

https://github.com/airblade/paper_trail
a bunch more here: https://www.ruby-toolbox.com/categories/Active_Record_Versioning

What these typically do is create a versions table and (once you add the versioning declaration in your model) they will save a diff of your versioned model every time it gets updated.

