title: Ruby on Rails - call Controller Method and pass Parameters to it
body: <p>I have following situation:</p>
  
  <p>I have a risk model and on my view it shows me a table with all risks. The table also includes a <code>check_box_tag</code>, as each risk should be able to be checked. In the tablehead there is a button and if this button is clicked, a method of the risk controller should be called, and it should have all checked risk IDs as parameter.</p>
  
  <p>Actually, I don't know which would be the best way to solve this.</p>
  
  <p>I have following code so far:</p>
  
  <p>View:</p>
  
  <pre><code>&lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;Risk Name&lt;/th&gt;
        &lt;th&gt;
          &lt;button id="mergerisks"&gt;Merge Risks&lt;/button&gt;
        &lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
       &lt;% Risks.all.each do |risk| %&gt;
          &lt;tr&gt;
            &lt;td&gt;&lt;%= risk.name %&gt;&lt;/td&gt;
            &lt;td&gt;&lt;%= check_box_tag 'mergerisks', risk.id %&gt;
            &lt;/td&gt;
          &lt;/tr&gt;
       &lt;% end %&gt;
   &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>  $( "#mergerisks" ).on( "click", function() {
      var selectedriskmerge = new Array();
      $("input:checked").each(
        function() {
          selectedriskmerge.push($(this).val());
      });
    });
  </code></pre>
  
  <p><strong>Edit</strong>
  Added the following ajax call to javascript</p>
  
  <pre><code>$.ajax({
    url: '/riskmerge',
    data:selectedriskmerge,
    success:function() {
    window.alert("Success!");
    }
  });
  </code></pre>
  
  <p>For now the Button only triggers the Javascript, and there are the ID's of all checked Risks are stored in an array.</p>
  
  <p>But now I don't know what would be the best way to call a controller method in the risk controller and pass the IDs of all checked Risks to the method.</p>
  
  <p>Thanks for any help.</p>