Forum: Ruby on Rails Simple things like duplicating a record in rails?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D167461db018fb93fa36587b3def84cf?d=identicon&s=25 Andreas Kviby (Guest)
on 2007-07-20 12:20
(Received via mailing list)
Maybe I am totally waisted after a long nights work with my admin
interface filters but how the heck can I duplicate records?

Scenario:
My client will enter hundreds maybe thousands of products into their
new nice e-commerce system backoffice forms. They call me and say,
Hey! Can we press a "DUPLICATE" button would safe us hours and hours
of time when adding products.

Solution?
I can't find any posts about this issues on the lists archives or
anywhere else for that matter. I just want to have in my scaffolds
next to show, edit, destroy a new link with the label "Duplicate and
Edit" and if you press this link it should take the data on the
selected product, copy it to a new product and go to the edit screen
of that new product.

Any ideas on how to accomplish this?
Cb98c59a6ff22c72676e756bbd28f266?d=identicon&s=25 Jacob Atzen (Guest)
on 2007-07-20 12:38
(Received via mailing list)
Andreas Kviby wrote:
> I can't find any posts about this issues on the lists archives or
> anywhere else for that matter. I just want to have in my scaffolds
> next to show, edit, destroy a new link with the label "Duplicate and
> Edit" and if you press this link it should take the data on the
> selected product, copy it to a new product and go to the edit screen
> of that new product.
>
> Any ideas on how to accomplish this?

How about object.clone?

--
Cheers,
- Jacob Atzen
D7c511ce5025d37b8c6bd9134e0f2bd9?d=identicon&s=25 Thorsten (Guest)
on 2007-07-20 12:43
(Received via mailing list)
#controller
def duplicate_and_edit
 @product = Product.find(params[:id]
 @product.id = nil
end

if your form in new.rhtml is populated with form_for @product ...... ,
you could just render this action and rails will fill in the values
into the form and thus reuse this view instead a creating a duplicate
form for this action.
D167461db018fb93fa36587b3def84cf?d=identicon&s=25 Andreas Kviby (Guest)
on 2007-07-20 13:40
(Received via mailing list)
Hi
Thanks a lot, it worked like a charm. Thanks to you guys my client
will be very happy today. /Andreas

Read my blog at www.swerails.se
This topic is locked and can not be replied to.