title: How to pass two object at a time to the template using Rails Ajax call
body: <p>I want to pass two object to the template which is going to render after Ajax call using Rails 3.See my below controller file.</p>
  
  <blockquote>
    <p>controller/homes_controller.rb</p>
  </blockquote>
  
  <pre><code>class HomesController &lt; ApplicationController
      def home
          @sdf=TSdf.new
          respond_to do |format|
            format.html
            format.js
          end
      end
      def scan_report
          @sdf=TSdf.find_by_Receipt_No(params[:sdf][:Receipt_No])
          @hcsy=THcsy.find_by_Sdp_Id(@sdf.Sdp_Id)
  
      end
  end
  </code></pre>
  
  <p>In the scan_report action from the above file I have created two object to access DB values and using these two object i have ti display data in this below template.</p>
  
  <blockquote>
    <p>view/homes/_hcsy_output_table.html.erb</p>
  </blockquote>
  
  <pre><code>&lt;div class="block-title"&gt;
          &lt;div class="block-options"&gt;
              &lt;a href="javascript:void(0)" class="btn btn-option enable-tooltip" data-toggle="block-collapse" title="Toggle block's content"&gt;&lt;i class="fa fa-arrow-up"&gt;&lt;/i&gt;&lt;/a&gt;
          &lt;/div&gt;
              &lt;h4&gt;Harischandra Sahayata Yojana Form&lt;/h4&gt;
      &lt;/div&gt;
      &lt;!--1st_total_div--&gt;
      &lt;div class="block-content"&gt;
        &lt;div class="block block-themed themed-asphalt"&gt;
        &lt;div class="block-title"&gt;&lt;h5&gt;Personal Details&lt;/h5&gt;&lt;/div&gt;
              &lt;div class="block-content full"&gt;
                      &lt;div class="totalaligndiv"&gt;
                        &lt;div class="input-group bmargindiv1 col-md-6 pull-left"&gt;&lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Receipt No :&lt;/div&gt;&lt;/span&gt;
                          &lt;input type="text" class="form-control" value= "&lt;%= @sdf.Receipt_No %&gt;"&gt; 
                        &lt;/div&gt;
                        &lt;div class="input-group bmargindiv1 col-md-6 pull-left"&gt;&lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Date &amp;amp; Time :&lt;/div&gt;&lt;/span&gt;
                          &lt;input type="text" class="form-control" value= "&lt;%= @hcsy.Created_On %&gt;"&gt; 
                        &lt;/div&gt;
                        &lt;div class="input-group bmargindiv1 col-md-6 pull-left"&gt;&lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Name of Deceased :&lt;/div&gt;&lt;/span&gt;
                          &lt;input type="text" class="form-control" placeholder="Name of Deceased"&gt; 
                        &lt;/div&gt;
                        &lt;div class="input-group bmargindiv1 col-md-6 pull-left"&gt; &lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Mobile No :&lt;/div&gt;&lt;/span&gt;
                          &lt;input type="text" class="form-control" placeholder="Mobile No"&gt; 
                        &lt;/div&gt;
                        &lt;div class="input-group bmargindiv1 col-md-6 pull-left"&gt;&lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Beneficiary Name :&lt;/div&gt;&lt;/span&gt;
                          &lt;input type="text" class="form-control" placeholder="Beneficiary Name"&gt; 
                        &lt;/div&gt;
                        &lt;div class="input-group bmargindiv1 col-md-6 pull-left"&gt; &lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Occupation :&lt;/div&gt;&lt;/span&gt;
                          &lt;input type="text" class="form-control" placeholder="Occupation"&gt; 
                        &lt;/div&gt;
                        &lt;div class="input-group bmargindiv1 col-md-12 pull-left"&gt; &lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Relation with Deceased :&lt;/div&gt;&lt;/span&gt;
                          &lt;input type="text" class="form-control" placeholder="Relation with Deceased"&gt; 
                        &lt;/div&gt;
                        &lt;div class="input-group bmargindiv1 col-md-6 pull-left"&gt; &lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Address Line - I :&lt;/div&gt;&lt;/span&gt;
                          &lt;textarea name="versions comments" placeholder="Address" class="form-control" rows="3"&gt;&lt;/textarea&gt;
                        &lt;/div&gt;
                        &lt;div class="input-group bmargindiv1 col-md-6 pull-left"&gt; &lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Address Line - II :&lt;/div&gt;&lt;/span&gt;
                          &lt;textarea name="versions comments" placeholder="Address" class="form-control" rows="3"&gt;&lt;/textarea&gt;
                        &lt;/div&gt;
                        &lt;div class="input-group bmargindiv1 col-md-6 pull-left"&gt; &lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Village/City :&lt;/div&gt;&lt;/span&gt;
                          &lt;input type="text" class="form-control" placeholder="Village/City"&gt; 
                        &lt;/div&gt;
                        &lt;div class="input-group bmargindiv1 col-md-6 pull-left"&gt; &lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Block :&lt;/div&gt;&lt;/span&gt;
                          &lt;input type="text" class="form-control" placeholder="Block"&gt; 
                        &lt;/div&gt;
                        &lt;div class="input-group bmargindiv1 col-md-6 pull-left"&gt; &lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;District :&lt;/div&gt;&lt;/span&gt;
                          &lt;input type="text" class="form-control" placeholder="District"&gt; 
                        &lt;/div&gt;
                        &lt;div class="input-group bmargindiv1 col-md-6 pull-left"&gt; &lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;State :&lt;/div&gt;&lt;/span&gt;
                          &lt;input type="text" class="form-control" placeholder="State"&gt; 
                        &lt;/div&gt;
                        &lt;div class="input-group bmargindiv1 col-md-6 pull-left"&gt; &lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Country :&lt;/div&gt;&lt;/span&gt;
                          &lt;input type="text" class="form-control" placeholder="Country"&gt; 
                        &lt;/div&gt;
                        &lt;div class="input-group bmargindiv1 col-md-6 pull-left"&gt; &lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Police Station :&lt;/div&gt;&lt;/span&gt;
                          &lt;input type="text" class="form-control" placeholder="Police Station"&gt; 
                        &lt;/div&gt;
                        &lt;div class="clearfix"&gt;&lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="totalaligndiv"&gt;
              &lt;div class="col-md-6" style="padding-left:0px;"&gt;
              &lt;div class="block block-themed themed-asphalt"&gt;
                  &lt;div class="block-title"&gt;&lt;h5&gt;Annual Income From Sources&lt;/h5&gt;&lt;/div&gt;
                      &lt;div class="block-content full"&gt;
                          &lt;div class="totalaligndiv"&gt;
                            &lt;div class="input-group bmargindiv1 col-md-12 pull-left"&gt;&lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;BPL :&lt;/div&gt;&lt;/span&gt;
                              &lt;input type="text" class="form-control" placeholder="BPL"&gt; 
                            &lt;/div&gt;
                            &lt;div class="input-group bmargindiv1 col-md-12 pull-left"&gt;&lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Govt. Services :&lt;/div&gt;&lt;/span&gt;
                              &lt;input type="text" class="form-control" placeholder="Govt. Services"&gt; 
                            &lt;/div&gt;
                            &lt;div class="input-group bmargindiv1 col-md-12 pull-left"&gt;&lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Business :&lt;/div&gt;&lt;/span&gt;
                              &lt;input type="text" class="form-control" placeholder="Business"&gt; 
                            &lt;/div&gt;
                            &lt;div class="input-group bmargindiv1 col-md-12 pull-left"&gt; &lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Land Property :&lt;/div&gt;&lt;/span&gt;
                              &lt;input type="text" class="form-control" placeholder="Land Property"&gt; 
                            &lt;/div&gt;
                            &lt;div class="input-group bmargindiv1 col-md-12 pull-left"&gt; &lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Others :&lt;/div&gt;&lt;/span&gt;
                              &lt;input type="text" class="form-control" placeholder="Others"&gt;
                            &lt;/div&gt;
                            &lt;div class="input-group bmargindiv1 col-md-12 pull-left" style="height:55px;"&gt;
                            &amp;nbsp; 
                            &lt;/div&gt;
                            &lt;div class="clearfix"&gt;&lt;/div&gt;
                      &lt;/div&gt;
                      &lt;/div&gt;
              &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="col-md-6" style="padding-right:0px;"&gt;
                &lt;div class="block block-themed themed-asphalt"&gt;
                      &lt;div class="block-title"&gt;&lt;h5&gt;Application Details&lt;/h5&gt;&lt;/div&gt;
                      &lt;div class="block-content full"&gt;
                          &lt;div class="totalaligndiv"&gt;
                            &lt;div class="input-group bmargindiv1 col-md-12 pull-left"&gt;&lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Select Purpose :&lt;/div&gt;&lt;/span&gt;
                              &lt;input type="text" class="form-control" placeholder="Select Purpose"&gt; 
                            &lt;/div&gt;
                            &lt;div class="input-group bmargindiv1 col-md-12 pull-left"&gt;&lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Amount Required :&lt;/div&gt;&lt;/span&gt;
                              &lt;input type="text" class="form-control" placeholder="Amount Required"&gt; 
                            &lt;/div&gt;
                            &lt;div&gt;Has he/she received any assistance earlier from this fund&lt;/div&gt;
                            &lt;div class="input-group bmargindiv1 col-md-12 pull-left"&gt;
                            &lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Status :&lt;/div&gt;&lt;/span&gt;
                              &lt;input type="text" class="form-control" placeholder="Status"&gt; 
                            &lt;/div&gt;
                            &lt;div class="input-group bmargindiv1 col-md-12 pull-left"&gt; &lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Prev. Receipt No. :&lt;/div&gt;&lt;/span&gt;
                              &lt;input type="text" class="form-control" placeholder="Prev. Receipt No."&gt; 
                            &lt;/div&gt;
                            &lt;div class="input-group bmargindiv1 col-md-12 pull-left"&gt; &lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Amount Received :&lt;/div&gt;&lt;/span&gt;
                              &lt;input type="text" class="form-control" placeholder="Amount Received"&gt; 
                            &lt;/div&gt;
                            &lt;div class="input-group bmargindiv1 col-md-12 pull-left"&gt; &lt;span class="input-group-addon text-left"&gt;&lt;div class="leftsidetextwidth"&gt;Date of Received :&lt;/div&gt;&lt;/span&gt;
                              &lt;input type="text" class="form-control" placeholder="Date of Received"&gt; 
                            &lt;/div&gt;
                            &lt;div class="clearfix"&gt;&lt;/div&gt;
                      &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="clearfix"&gt;&lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="tpaddingdiv1"&gt;
              &lt;div class="col-md-4"&gt;
                  &lt;div class="text-center bpaddingdiv1"&gt;&lt;img src="image/personsphoto.png" border="0" name="signature" height="140" class="borderblackdiv"&gt;&lt;/div&gt;
                  &lt;div class="fontweightbolddiv fontssizediv3 text-center bpaddingdiv1"&gt;Deceased Photo&lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="col-md-4"&gt;
                  &lt;div class="text-center bpaddingdiv1"&gt;&lt;img src="image/personsphoto.png" border="0" name="signature" height="140" class="borderblackdiv"&gt;&lt;/div&gt;
                  &lt;div class="fontweightbolddiv fontssizediv3 bpaddingdiv1 text-center"&gt;Donor Photo&lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="col-md-4"&gt;
                  &lt;div class="text-center bpaddingdiv1"&gt;&lt;img src="image/signaturetwo.jpg" border="0" name="signature" height="140" class="borderblackdiv"&gt;&lt;/div&gt;
                  &lt;div class="fontweightbolddiv fontssizediv3 bpaddingdiv1 text-center"&gt;Donor Thumb&lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="clearfix"&gt;&lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>Check the above file I can access only values by @sdf but can not access value by @hcsy which i need.So please help me to fetch data by @hcsy object from db to this above template.My other related files are given below.</p>
  
  <blockquote>
    <p>scan_report.js.erb:</p>
  </blockquote>
  
  <pre><code>$("#hcsy_block").html("&lt;%= escape_javascript (render 'hcsy_output_table',locals: "{hcsy: @hcsy }" ) %&gt;");
  $("#hcsy_block").slideDown(350);
  </code></pre>
  
  <blockquote>
    <p>scan_report.html.erb:</p>
  </blockquote>
  
  <pre><code>&lt;%= render 'hcsy_output_table',locals: "{hcsy: @hcsy }" %&gt;
  </code></pre>
  
  <p>The _hcsy_output_table.html.erb will render on the home page within div id "hcsy_block".I can only access through @sdf object but i need also data using @hcsy object.Please help me to access data by @hcsy object and let me to know where i have done the mistake.</p>