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

  • SEARCH
  • Home
  • 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 7580777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:00:05+00:00 2026-05-30T18:00:05+00:00

How do I loop through params in my controller so that I can change

  • 0

How do I loop through params in my controller so that I can change their values?

This:

...
params[:contact][:relationships_attributes].each do |rel|
  rel[:contact_ids] = [rel[:contact_ids]]
end
...

Returns an Error of:

# can't convert Symbol into Integer

To provide more context I am using a single select box in place of a multi-select. So the controller is expecting an array but instead its getting a single value.

Here Are My Params:

{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"8FrW59t9vzSep+jEGceMdE/b5q69i5hrEp08yZJJk0o=",
"contact"=>
  {"first_name"=>"John",
   "last_name"=>"Smith",
   "email_addresses_attributes"=>
    {"0"=>
      {"value"=>"john.smith@gmail.com",
       "type"=>"Home",
       "_destroy"=>"false",
       "id"=>"4f4eea6dbe5a2ccf03000031"
      },
       "1"=>{"value"=>"john@smith.com",
       "type"=>"Home",
       "_destroy"=>"false",
       "id"=>"4f4eea7dbe5a2ccf03000035"
      }
    },
  "phone_numbers_attributes"=>
    {"0"=>
      {"value"=>"555-334-5959",
       "type"=>"Home",
       "_destroy"=>"false",
       "id"=>"4f4eea64be5a2ccf0300002c"}
    },
  "addresses_attributes"=>
    {"0"=>
      {"type"=>"Home",
       "street_address"=>"12345 Any Rd",
       "city"=>"Anytown",
       "state"=>"CO",
       "country"=>"United States",
       "_destroy"=>"false",
       "id"=>"4f4eea64be5a2ccf0300002d"
      }
    },
  "relationships_attributes"=>
    {"1330623965418"=>
      {"contact_ids"=>"4f4e6696be5a2ca2a7000045",
       "title"=>"Wife",
       "_destroy"=>"false"
      }
    }
  },
  "commit"=>"Update Contact",
  "id"=>"4f4e6696be5a2ca2a7000045"
}
  • 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-30T18:00:06+00:00Added an answer on May 30, 2026 at 6:00 pm

    When you use each on a Hash like this:

    params[:contact][:relationships_attributes].each do |rel|
    

    the block argument, rel, is actually a two element Array with the key at position 0 and the value at position 1. Then your block tries to access the Array as though it was a Hash:

    rel[:contact_ids]
    

    and that explains your error message: you can’t index an Array with a Symbol.

    I think you want to do something more like this:

    params['contact']['relationships_attributes'].each do |k, v|
      v['contact_ids'] = [ v['contact_ids'] ] unless v['contact_ids'].is_a?(Array)
    end
    

    That will give you a structure like this:

    {
      :contact => {
        :relationships_attributes => {
          '1330623965418' => {
            :contact_ids => ['4f4e6696be5a2ca2a7000045']
            :title => 'Wife',
            :_destroy => 'false'
          }
          ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I loop through all members in a JavaScript object, including values that
I know I can loop through a list of strings like this: list<string>::iterator Iterator;
How can I loop through a Comma separated string which I am passing as
I have a list of entites that contains ~137000 records that I loop through
I have a very simple each loop written in Ruby : params[:category].each do |i|
I'm trying to loop through the arguments that I am passing to a batch
How can I loop through the rows of a DataGridView one at a time
I upload through a form a file and in the controller this file read.
I loop through a bunch of directories recursively. Some of them (like D:\$RECYCLE.BIN\S-1-5-20 )
I need to loop through all the matches in say the following string: <a

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.