How to create a new or update if an existing product is in rails

I have an action that saves new procucts as follows:

@products = Product.new(params[:product]) 
@products.save

I invoke the same action to edit the product. But every time I edit ... a new product is created (due to the above statements).

While before I saw some function that will create a new record only if there is no record. create_or_updatesomething like that. I can not find it now.

Can someone tell me what this method is? or give me a better approach for this?

+3
source share
1 answer
+3

Source: https://habr.com/ru/post/1730689/


All Articles