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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:03:58+00:00 2026-06-01T19:03:58+00:00

I’m trying to update one field of multiple records in a model, Lead. Each

  • 0

I’m trying to update one field of multiple records in a model, Lead. Each lead is displayed in a table row, and the field being modified for the multiple rows is “selected”, which is a boolean, stored as tinyint 1 or 0, true or false.

leads_controller.rb

  def list
    @leads = Lead.where({:store_number => session[:store_number]}).order("selected DESC")
    @targeted_leads = Lead.where(:store_number => session[:store_number], :selected => true)
  end

  def update_multiple
    @leads = Lead.find(params[:lead_ids])
    @leads.update(params[:lead_ids])
    redirect_to(:action => 'list')
  end

list.html.erb

<%= form_tag update_multiple_leads_path, :method => :put do %>
<table>
  <thead>
    <tr>
      <th>Lead Name</th>
      <th>Selected Leads</th>
    </tr>
  </thead>
  <tbody>
  <% for lead in @leads %>
    <tr>
        </td>
      <td><%= lead.company_name %></td>
      <td>
        <%= fields_for("lead_ids[]", lead) do |f| %>
          <%= f.check_box("selected") %>
        <% end %>
      </td>
    </tr>
  <% end %>
  </tbody>
</table>
<%= submit_tag('Save Targeted Leads', :class => "btn") %>
<% end %>

Now, what I want this form to do is pass all leads through, and if checked, update that record’s “selected” field to 1, and if unchecked, update the field to 0.

When it passes along, here are the results on the update_multiple action:

ArgumentError in LeadsController#update_multiple

Unknown key: 6
Rails.root: (my/rails/root)

Application Trace | Framework Trace | Full Trace
app/controllers/leads_controller.rb:73:in `update_multiple'
Request

Parameters:

{"commit"=>"Save Targeted Leads",
 "lead_ids"=>{"6"=>{"selected"=>"1"},
 "1"=>{"selected"=>"0"},
 "3"=>{"selected"=>"0"}},
 "authenticity_token"=>"ALYtIkJNsAANsHXaAvgeb84G9Ms7OPSkyFO6jkM19yU=",
 "_method"=>"put",
 "utf8"=>"\342\234\223"}

FYI: (Line 73 references this row in my controller: @leads = Lead.find(params[:lead_ids]) )
When I look at this, it looks like it’s passing everything along, just as I’d want it to… Lead Model, take id 6, set selected to 1. Now take id 1, set selected to 0. What’s really confusing me is that “Unknown key” bit.
My initial thoughts are, it’s not looking for the right field to modify… as in, it knows I’m looking for “6”, but what about “6”? “6” is not a key. Id 6, or something else?
Has anyone else solved this? Thank you in advance for your thoughts.

  • 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-06-01T19:04:00+00:00Added an answer on June 1, 2026 at 7:04 pm

    Figured it out! Took me days (I’m pretty new to ruby), but I got something to work. This will only work in this particular case, because it’s not flexible… Rails probably has a better way to do this, but for others that are stuggling:

      def update_multiple
        params[:lead_ids].each do |lead|
          record = Lead.find(lead[0])
          record.update_attributes(lead[1[0]], lead[1[1]])
        end
    
        redirect_to(:action => 'index')
      end
    

    Of note, in regards to a previous comment, it’s irrelevant (at least for my purposes) that the id comes through as a string, so no need to hash… but if you wanted to do that, I wrote this while debugging.

    the_hash = Hash[params[:lead_ids].map {|key, array| [key.to_i, array]}]
    

    Then pass the hash in to the each loop, so…

    the_hash.each do |lead|
    

    It’s manually looping through each param and assigning based on the index. So for each id (for example, 1), it’s taking the first index of that id’s array, and manually assigning it to the second index of the same array.

    Again, not very Rails-like, and definitely not THE way to do it, but it works. Anyone with a better way, feel free to contribute.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

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.