Note that there are some explanatory texts on larger screens.

plurals
  1. POdelete action not working in Rails 3
    primarykey
    data
    text
    <p>we have an requirement where all the products are displayed with the checkbox next to each product name. </p> <p>index.html.erb</p> <pre><code>&lt;%= form_tag users_path, :method =&gt; 'get' do %&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="checkbox" name="cb1", id="cb1" /&gt; &lt;/td&gt; &lt;td&gt; Mobiles &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="checkbox" name="cb2", id="cb2" /&gt; &lt;/td&gt; &lt;td&gt; Laptops &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;%= link_to 'Add User', "/users/new", :method =&gt; :get, :target =&gt; "_blank"%&gt; &lt;/td&gt; &lt;td&gt; &lt;%= link_to 'Delete User(s)', :method =&gt; :delete, :onclick =&gt; &gt; "onDeleteClick();" %&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;% end %&gt; </code></pre> <p>i have got an javascript function which gets me the list of products selected and i am using substring of id i.e. if cb1 is the id of checkbox then 1 is the product id and am forming the list of product id's as 1,2,3.</p> <p>ProductsController.rb delete action in the products controller. </p> <pre><code>def delete User.delete( params[:selecteduserids]) render :action =&gt; "index" end Note: &lt;%= hidden_field_tag :selecteduserids, params[:selecteduserids] %&gt; </code></pre> <p>Javascript:</p> <pre><code>function onDeleteClick() { var objlist = document.getElementById('dvproductdetails'); var aList = objlist.getElementsByTagName('input'); var nLen = aList.length; var nSelCnt = 0; var arSelectedProductIDs = new Array(); for (var n=0; n&lt;nLen; n++) { var oChk = aList[n]; if (oChk.type == 'checkbox' &amp;&amp; oChk.id.substring( 0, 2) == 'cb' &amp;&amp; oChk.checked) { arSelectedProductIDs[nSelCnt] = oChk.id.substring( 2, oChk.id.toString().length); nSelCnt = nSelCnt + 1; } } if( arSelectedProductIDs.length &gt; 0) { document.getElementById('selectedproductids').value = arSelectedProductIDs.toString(); //alert(arSelectedProductIDs.toString()); return true; } else { alert('Please select the Product to delete.'); } return false; } </code></pre> <p>Issue: When i click on Delete link, the action is not executed. Can anyone guide me in getting solved the issue?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload