Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3955680
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:15:54+00:00 2026-05-20T02:15:54+00:00

Rails 2.3.5 I have a contact model with ‘directory_id’ and ‘folder_id’ foreign keys. On

  • 0

Rails 2.3.5

I have a contact model with ‘directory_id’ and ‘folder_id’ foreign keys.

On an index page I have the form to select multiple contacts for the purpose of making a copy of those contacts to a different directory/folder. When the form is submitted, the following params exist (which are all the Contact id’s and the Directory and Folder foreign keys):

> "selected_contacts"=>["9", "14", "10", "13", "12", "11"]
> "copy_to_directory"=>"66"  (will be directory_id in Contacts)
> "copy_to_folder"=>"59"     (will be folder_id in Contacts)

So, I need to find all the contact records, change out the directory_id’s and folder_id’s and save them as new records (copies).

As far as I know, clone (for a copy with a blank id field) only works on a single record, and save only works on a single record. The only thing I can think of right now would be to loop through each of the “slected_contacts”, finding, modifiying and then saving them seperately.

Is there an easy way to do this, or how should I go about doing this?

Thank You!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T02:15:55+00:00Added an answer on May 20, 2026 at 2:15 am

    Loading all selected contacts in one statement could be done like this:

    selected_contacts = Contacts.find ["9", "14", "10", "13", "12", "11"]
    

    For cloning those contacts and saving the new copies, I think there is no easier way than implementing a loop.

    selected_contacts.each do |contact|
        contact_clone = contact.clone
        # manipulate contact_clone
        contact_clone.save
    end
    

    If that’s no efficient enough in your case you’ll probably have to write custom SQL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rails app where i have a Contact model and with an
Rails 2.3.5 I have a Folder model and a Contact Model. In a view,
I am using rails 3.2.3 and gmaps4rails gem. I have one model called contact.
I have a rails model that I am adding validations to and I seem
Using Rails 3 active relation, I have a scope: scope :duplicate_contact, lambda {|contact| where(
I have a Rails 3 simple scaffolded application having one model like that: class
I have created a contact form which will email me once sent. Now I
I have a task to develop a rails application following the model for routing.
I'm creating a Rails app, and I have a model called User . In
I'm a bit confused about STI in rails. My situation: I have a Contact

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.