Topic: creating and updating records simultaneously
I have this following question in rails.
I have 2 tables product and history
id name type price location
1 abc electronics $180 aisle1
id product_id status
1 1 price changed from $200 to $180
Whenever the product price or location is updated by a user by hitting the update button,
1) the changes should automatically be reflected in the history status column(as shown above) without the user having to enter that manually. For example
if the price is updated from 200 to 180 then a new history row will be created with new id and the status column will say ' price changed from $200 to $180'
if the location is updated from aisle1 to aisle 2 then status displays ' loc changed from ailse1 to aisle 2'
I am trying to do something like this though I dont know whether this approach is correct
@product = Product.new(params[:product])
@history.new(attributes) ==> I am not sure how to assign the attributes here
I would really appreciate if someone could tell me how a new history row can be automatically created in this case when a new product is created or an existing product is updated.