Default action performed by jQuery on the partial data in ruby on rails

Problem :- Default action performed by jQuery on the partial data in ruby on rails

description :- I am attempting the following. A customer select option in the main form. when a user selects a customer in the main form his bills should appear in a select format in all the subsequent partials. Nested form gem is being used to get the partial.

Problem :- as i select the customer i am able to get the customer data, here the customer bills, but i am not able to post the data in the partial. the div id where i am supposed to post the data is not been detected. Bills concerning only the customer selected, does not appear in the partial.

solutions Tried. 1. rewrote the entire code thinking problem might be with the data but failed.

2. changed the environment to windows thinking problem with the environment but the same problem is appearing in windows too.

3. created a test project with one field in main form and one field in the partial to see if the problem is there in the main project but same error appears in the test project also.

4. Tried to send customer data to the partial and yet still the same error appears.

5. shifted the entire employee, customer and supplier code to partial. this solves the problem of getting bills, but allows user to select employee or supplier in the subsequent partials, fails validation, because each partial is a separate entity and changes done in first partial is not reflected in subsequent partial.

6. tried to achieve the above problem without using jquery with rails code but java-script is very much required.

7. changed the nested form gem to cocoon gem thinking the problem is with the gem, but the same problem occurs.

Your description is so vague that it is impossible to provide useful help. First have a look at the Rails Guide on Debugging, this will show you techniques to help debug your code. Using those techniques work out exactly where the problem is arising. Once you know where the problem is arising then if you still cannot see the answer post again here showing the section of the code that is not working as you expect.

Colin

Colin Law wrote in post #1089479:

sharath chander punthambekar wrote in post #1089481:

Colin Law wrote in post #1089479:

here the customer bills, but i am not able to post the data in the partial. the div id where i am supposed to post the data is not been detected. Bills concerning only the customer selected, does not appear in the partial.

Your description is so vague that it is impossible to provide useful help. First have a look at the Rails Guide on Debugging, this will show you techniques to help debug your code. Using those techniques work out exactly where the problem is arising. Once you know where the problem is arising then if you still cannot see the answer post again here showing the section of the code that is not working as you expect.

Colin

Thank you Colin. I will revert back with the code strip shortly. Sorry to have been vague. Sharath

I am attempting the following. A customer select option in the main form. when a user selects a customer in the main form his bills should appear in the all the subsequent partials.

I am using ryan bates's nested_form gem to get the partial. the code is as follows. <%= simple_nested_form_for @money_receipt do |f| %>

    <div class="customers"><%= f.collection_select :customer_id, Customer.all, :id, :name, options ={:prompt => "-Select a Customer"}, :style=>'width:210px;'%></div><br />     /*rest of the code*/

    <%= f.link_to_add "Add line items", :money_receipt_line_items %>

inside the partial <div class="bill"> <%= f.collection_select :customer_bill_id, CustomerBill.all,:id,:id, {:prompt => "Select Customer bill"}, :style => 'width:202px;' %></div><br />

/*rest of the code*/

the jQuery code for the above is as follows jQuery(document).ready(function(){    jQuery(".customers select").bind("change", function() {       var data = {         customer_id: jQuery(this).val()       }       jQuery.getJSON(          "/money_receipts/get_bills",         data, function(data){       var result = "",a,x;       var b = "<option>Select customer Bill</option>"       for(i=0;i<data.length; i++)       {        a = data[i];        result = result + "<option value="+a[0]+">"+a[0]+"</option>";        console.log(result);       }      child=jQuery('.bill select').html(b+result);     });     });   });

and finally in the controller i have. def get_bills @bill_amount = CustomerBill.find_all_by_customer_id(params[:customer_id]).map{|bill| [bill.id]} if params[:customer_id]     respond_to do |format|       format.json { render json: @bill_amount }     end   end