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 7008445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:44:08+00:00 2026-05-27T21:44:08+00:00

I’m implementing a form based on Ryan Bate’s [always excellent] Railscast, #52, Update Through

  • 0

I’m implementing a form based on Ryan Bate’s [always excellent] Railscast, #52, Update Through Checkboxes, http://railscasts.com/episodes/52-update-through-checkboxes

In my case, I’m actually wanting to pass through an array of ids for each checkbox selected.

The key line in my form looks like this,

<td"><%= check_box_tag "sales_ids[]", batch["sales_ids"] %></td>

batch[“sales_ids] itself is an array of ids, and the outcome I’m wanting is for an array of all the checked items (each representing an array of ids) to be passed along.

If I inspect the individual batch[“sales_ids”] from the form, then I can confirm it is indeed an array, for example, [3907, 3908, 3909] (remember, I want to pass along an array of these items for each row checked)

The key line from the method that handles the form looks like this,

params[:sales_ids].each { |batch| Sales.update_all(["code=?", 99], :id => batch) }

The intent of this code, again based on the Railscast example, is to iterate over the array of arrays, and update each sub-array of ids.

When I examine the received array, I see, [“5412”, “3907 3908 3909”, “2452”]

The sub-array isn’t handled as an array and (for reasons I don’t understand) only the first item each ‘substring’ (in this case “5412”, “3907”, “2452”) is updated.

It seems that the passed subarray isn’t actually an array, or something else is awry.

I’d appreciate help in how to pass and receive these ids as an array of arrays. Thanks.

  • 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-27T21:44:09+00:00Added an answer on May 27, 2026 at 9:44 pm

    as far as I know, passing arrays of arrays in this way won’t work via a form. However there is a work around that should work fine for you.

    in the view do this for your checkboxes: (I’m assuming batch[“sales_ids”] is an array)

    <%= check_box_tag "sales_ids[]", batch["sales_ids"].join(",") %>
    

    And in your controller do this:

    params[:sales_ids].collect{|a| a.split(",") }.each { |batch| Sales.update_all(["code=?", 99], :id => batch) }
    

    Instead of passing an array of arrays, we are now passing an array of comma separated values. In the controller these comma separated values are turned into an array.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to loop through a bunch of documents I have to put
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.