Save as new?


#1

@row = Post.find(5)

How can I save it as a new row?

Post.new(@row) ?? Do I need to destroy an old id?


#2

Fresh M. wrote:

@row = Post.find(5)

How can I save it as a new row?

Post.new(@row) ?? Do I need to destroy an old id?

Did you have a look at ActiveRecord::clone
(http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002278) ?

The following might work for you :

@row = Post.find(5)
clone = @row.clone
clone.save

(NB: The associations won’t be cloned, only attributes)