@row = Post.find(5)
How can I save it as a new row?
Post.new(@row) ?? Do I need to destroy an old id?
@row = Post.find(5)
How can I save it as a new row?
Post.new(@row) ?? Do I need to destroy an old id?
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
(ActiveRecord::Base) ?
The following might work for you :
@row = Post.find(5)
clone = @row.clone
clone.save
(NB: The associations won’t be cloned, only attributes)
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs