title: Rails 4 Update Multiple Records
body: <p>Been at this the last 2 days and can't figure out what I'm doing wrong. I'm trying to update multiple match_pick objects on a screen at the same time using <code>form_tag</code>. Bare <code>match_pick</code> records get created as soon as a user signs up. I then want the user to be able to update relevant info on these records and press a submit button. Here's what I have so far:</p>
  
  <blockquote>
    <p><strong>routes.rb</strong></p>
  </blockquote>
  
  <pre><code>post "match_picks/adjust_match_picks" =&gt; "match_picks#adjust_match_picks", :as =&gt; :adjust_match_picks
  </code></pre>
  
  <blockquote>
    <p><strong>match_picks_controller.rb</strong></p>
  </blockquote>
  
  <pre><code>def adjust_match_picks
    puts "The update_match_picks method has been called"
    @match_picks_recd = params[:match_picks]
    puts @match_picks_recd.inspect    
    puts "The parameters are:"
    puts params.inspect
    puts "The object passed is:"
  end
  </code></pre>
  
  <blockquote>
    <p><strong>views/match_picks/index.html.erb</strong></p>
  </blockquote>
  
  <pre><code>&lt;%= form_for adjust_match_picks_path, :method =&gt; :post do %&gt;
    &lt;% @match_picks.each do |pick| %&gt; 
      &lt;%= fields_for "match_picks[]", pick do |mp| %&gt;
        &lt;%= mp.text_field :id %&gt;
        &lt;%= mp.text_field :result_pick %&gt;
    &lt;% end %&gt;  
  &lt;% end %&gt;  
  </code></pre>
  
  <p>The HTML generated by the above is as follows:-</p>
  
  <pre><code>  &lt;form accept-charset="UTF-8" action="/match_picks" method="post"&gt;&lt;div style="display:none"&gt;&lt;input name="utf8" type="hidden" value="&amp;#x2713;" /&gt;&lt;input name="authenticity_token" type="hidden" value="EIEFdhjkkfnkjfYjlkjdlkjCzxaxHeaXbkvu0wbLB1QsOj+o=" /&gt;&lt;/div&gt;
  </code></pre>
  
  <p>The above code is giving the following error:</p>
  
  <pre><code>    ActionController::ParameterMissing in MatchPicksController#create
  
      param is missing or the value is empty: match_pick
  </code></pre>
  
  <p>It then highlights this paragraph</p>
  
  <pre><code>        def match_pick_params
            params.require(:match_pick).permit(:user_id, :match_id, :round_id, :result_pick, :team_id, :try_pick, :margin_id, :result_points, :try_points, :margin_points, :random, :closed)
          end
  </code></pre>
  
  <p>I've put some debug in each of the methods in the match_picks controller and the form submit seems to be triggering the <code>create</code> method of the controller instead of my custom <code>adjust_match_picks</code> method. It looks to me like the error is triggering because the create method is not being passed <code>match_pick_params</code>. But I don't want the <code>create</code> method triggering, I want my custom <code>adjust_match_picks</code> to trigger.</p>
  
  <p>I haven't put any code in to handle what's being passed to the <code>adjust_match_picks</code> as yet because I can't even get it to trigger.</p>
  
  <p>I'm hoping I'm doing something sill here as I'm at my wits end. Thanks for looking.</p>
  
  <blockquote>
    <p><strong>Edit 1</strong></p>
  </blockquote>
  
  <p>The parameters that are getting passed when the submit button is pressed are:</p>
  
  <pre><code>Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"EIEFdhjkkfnkjfYjlkjdlkjCzxaxHeaXbkvu0wbLB1QsOj+o=", "match_picks"=&gt;{"1"=&gt;{"id"=&gt;"1", "result_pick"=&gt;"6"}, "2"=&gt;{"id"=&gt;"2", "result_pick"=&gt;""}, "3"=&gt;{"id"=&gt;"3", "result_pick"=&gt;""}, "4"=&gt;{"id"=&gt;"4", "result_pick"=&gt;""}, "5"=&gt;{"id"=&gt;"5", "result_pick"=&gt;""}, "6"=&gt;{"id"=&gt;"6", "result_pick"=&gt;""}, "7"=&gt;{"id"=&gt;"7", "result_pick"=&gt;""}, "8"=&gt;{"id"=&gt;"8", "result_pick"=&gt;""}, "9"=&gt;{"id"=&gt;"9", "result_pick"=&gt;""}, "10"=&gt;{"id"=&gt;"10", "result_pick"=&gt;""}, "11"=&gt;{"id"=&gt;"11", "result_pick"=&gt;""}, "12"=&gt;{"id"=&gt;"12", "result_pick"=&gt;""}, "13"=&gt;{"id"=&gt;"13", "result_pick"=&gt;""}, "14"=&gt;{"id"=&gt;"14", "result_pick"=&gt;""}, "15"=&gt;{"id"=&gt;"15", "result_pick"=&gt;""}, "16"=&gt;{"id"=&gt;"16", "result_pick"=&gt;""}, "17"=&gt;{"id"=&gt;"17", "result_pick"=&gt;""}, "18"=&gt;{"id"=&gt;"18", "result_pick"=&gt;""}, "19"=&gt;{"id"=&gt;"19", "result_pick"=&gt;""}, "20"=&gt;{"id"=&gt;"20", "result_pick"=&gt;""}, "21"=&gt;{"id"=&gt;"21", "result_pick"=&gt;""}, "22"=&gt;{"id"=&gt;"22", "result_pick"=&gt;""}, "23"=&gt;{"id"=&gt;"23", "result_pick"=&gt;""}, "24"=&gt;{"id"=&gt;"24", "result_pick"=&gt;""}, "25"=&gt;{"id"=&gt;"25", "result_pick"=&gt;""}, "26"=&gt;{"id"=&gt;"26", "result_pick"=&gt;""}, "27"=&gt;{"id"=&gt;"27", "result_pick"=&gt;""}, "28"=&gt;{"id"=&gt;"28", "result_pick"=&gt;""}, "29"=&gt;{"id"=&gt;"29", "result_pick"=&gt;""}, "30"=&gt;{"id"=&gt;"30", "result_pick"=&gt;""}, "31"=&gt;{"id"=&gt;"31", "result_pick"=&gt;""}, "32"=&gt;{"id"=&gt;"32", "result_pick"=&gt;""}, "33"=&gt;{"id"=&gt;"33", "result_pick"=&gt;""}, "34"=&gt;{"id"=&gt;"34", "result_pick"=&gt;""}, "35"=&gt;{"id"=&gt;"35", "result_pick"=&gt;""}, "36"=&gt;{"id"=&gt;"36", "result_pick"=&gt;""}, "37"=&gt;{"id"=&gt;"37", "result_pick"=&gt;""}, "38"=&gt;{"id"=&gt;"38", "result_pick"=&gt;""}, "39"=&gt;{"id"=&gt;"39", "result_pick"=&gt;""}, "40"=&gt;{"id"=&gt;"40", "result_pick"=&gt;""}, "41"=&gt;{"id"=&gt;"41", "result_pick"=&gt;""}, "42"=&gt;{"id"=&gt;"42", "result_pick"=&gt;""}, "43"=&gt;{"id"=&gt;"43", "result_pick"=&gt;""}, "44"=&gt;{"id"=&gt;"44", "result_pick"=&gt;""}, "45"=&gt;{"id"=&gt;"45", "result_pick"=&gt;""}, "46"=&gt;{"id"=&gt;"46", "result_pick"=&gt;""}, "47"=&gt;{"id"=&gt;"47", "result_pick"=&gt;""}, "48"=&gt;{"id"=&gt;"48", "result_pick"=&gt;""}}, "button"=&gt;""}
  </code></pre>
  
  <blockquote>
    <p><strong>Edit 2 (SOLVED)</strong></p>
  </blockquote>
  
  <p>I've realised I was using a <code>form_for</code> instead of a <code>form_tag</code>. WHen I change it to <code>form_tag</code> my custom route fires. Silly mistake!! Thanks for looking</p>