You should use the ActiveRecord::Core#dup
method.
From the page:
Duped objects have no id assigned and are treated as new records. Note that this is a “shallow” copy as it copies the object’s attributes only, not its associations. The extent of a “deep” copy is application specific and is therefore left to the application to implement according to its need. The dup method does not preserve the timestamps (created|updated)_(at|on).
In short, @project.dup
will build a new Project
object with all parameters same as @project
except - id
, created_at
, updated_at
fields. @user2
can do modification on this newly build object and then save
it. This mimics the fork
feature.