如果没有在Rails 3中重新加载,数据库值不会出现在同一页面中

时间:2015-04-17 09:37:17

标签: ruby ajax ruby-on-rails-3

我希望在按收据编号搜索后,值应显示在同一页面中,而不使用Rails3重新加载页面。但我得到了所有的价值,但不是在同一页面。有人可以帮我解决这个问题吗?我在下面解释我的代码。

视图/舍/ home.html.erb

<% if current_admin %>  
<div id="page-container" class="full-width">
<header class="navbar navbar-inverse">
<div class="row">
<div class="col-sm-4 hidden-xs">
<ul class="navbar-nav-custom pull-left">
<li class="visible-md visible-lg">    
<a href="javascript:void(0)" id="toggle-side-content">
<i class="fa fa-bars"></i>
</a>
</li>
<li class="divider-vertical"></li>
</ul>
</div>
<div class="col-sm-4 col-xs-12 text-center">
<a href="index.html" class="navbar-brand" style="width:100%; line-height:19px;">
SWARGADWAR, PURI MUNICIPALITY<br>
<span class="fontssizediv2">Government of Odisha</span>
</a>
<div id="loading" class="display-none"><i class="fa fa-spinner fa-spin"></i></div>
</div>
<div id="header-nav-section" class="col-sm-4 col-xs-12 clearfix">
<ul class="navbar-nav-custom pull-left visible-xs visible-sm" id="mobile-nav">
<li>
<a href="javascript:void(0)" data-toggle="collapse" data-target=".navbar-main-collapse">
<i class="fa fa-bars"></i>
</a>
</li>
<li class="divider-vertical"></li>
</ul>
</div>
</div>
</header><aside id="page-sidebar" class="collapse navbar-collapse navbar-main-collapse">
<div class="side-scrollable">
<div class="mini-profile">
<div class="mini-profile-options">
<a href="/sessions/logout_admin" class="badge badge-danger" data-toggle="tooltip" data-placement="right" title="Log out">
<i class="fa fa-sign-out"></i>
</a>
</div>
<a href="javascript:void(0)">
<img src="/assets/personsphoto.png" alt="abhijeetca" class="img-circle" height="120" style="height:120px;">
</a>
</div>
<div class="sidebar-tabs-con">
<div class="tab-content" style="padding-top:0px;">
<div class="tab-pane active" id="side-tab-menu">
<nav id="primary-nav">
    <ul>
        <li>
        <a href="/homes/home" class="active"><i class="gi gi-display"></i>Dashboard</a>
        </li>
        <li>
        <a href="/reports/view_report"><i class="gi gi-table"></i>Report</a>
        </li>
    </ul>
</nav>
</div>
</div>
</div>
</div>
</aside><div id="pre-page-content">
<h1><i class="themed-color"><img src="/assets/odishalogo.png" border="0" name="odishalogo" style="height:80px;"></i><div class="tpaddingdiv2">(E-RECEIPT)</div></h1>
<div class="clearfix"></div>
</div>
<div id="page-content">
<ul class="breadcrumb breadcrumb-top">
<li>
<a href="index.html"><i class="gi gi-display"></i></a>
</li>
<li>Harischandra Sahayata Yojana Slip</li>
</ul>
<div class="tbpaddingdiv2">
    <div class="col-md-6" style="float:none; margin:auto;">
    <%= form_for :sdf ,:url => {:action => "scan_report" },remote: true do |f| %>
        <div class="input-group bmargindiv1 col-md-12"> <span class="input-group-addon text-left">Receipt No. Scan :</span>
        <%= f.text_field :Receipt_No,:class => "form-control",placeholder:"Receipt No. scan",:onchange => 'this.form.submit();' %>
    </div>
    <% end %>
    <div class="clearfix"></div>
</div>

<div class="block block-themed" id="hcsy_block" style="display:none;" >

</div>
</div>
<footer>
<div class="pull-right">
Maintained <i class="fa fa-pencil text-danger"></i> by <strong><a href="http://www.oditeksolutions.com" target="_blank">Oditek Solutions</a></strong>
</div>
<div class="pull-left">
<span id="year-copy"></span> &copy; <strong><a href="javascript:void(0)" target="_blank">Swargadwar, Puri Municipality</a></strong>
</div>
</footer>
</div>
<a href="#" id="to-top"><i class="fa fa-chevron-up"></i></a>
<% end %>

控制器/ homes_controller.rb:

class HomesController < ApplicationController
    def home
        @sdf=TSdf.new
    end
    def scan_report
        @sdf=TSdf.find_by_Receipt_No(params[:sdf][:Receipt_No])
        if @sdf && @sdf.HCSY_Status=='YES'
             @hcsy=THcsy.find_by_Sdp_Id(@sdf.Sdp_Id)
             respond_to do |format|
                format.html
                format.js 
             end
        else
            flash[:alert]="Scan number is invalid"
            flash[:color]="invalid"
            redirect_to :action => "home"
        end


    end
end

scan_report.js.erb

$("#hcsy_block").html("<%= escape_javascript( render(partial: "hcsy_output_table",locals: "{hcsy: @hcsy }" ) ) %>");
$("#hcsy_block").slideDown(350);

hcsy_output_table.html.erb

<div class="block-title">
        <div class="block-options">
            <a href="javascript:void(0)" class="btn btn-option enable-tooltip" data-toggle="block-collapse" title="Toggle block's content"><i class="fa fa-arrow-up"></i></a>
        </div>
            <h4>Harischandra Sahayata Yojana Form</h4>
    </div>
    <!--1st_total_div-->
    <div class="block-content">
      <div class="block block-themed themed-asphalt">
      <div class="block-title"><h5>Personal Details</h5></div>
            <div class="block-content full">
                    <div class="totalaligndiv">
                      <div class="input-group bmargindiv1 col-md-6 pull-left"><span class="input-group-addon text-left"><div class="leftsidetextwidth">Receipt No :</div></span>
                        <input type="text" class="form-control" value= "<%= hcsy.Receipt_No %>" > 
                      </div>
                      <div class="input-group bmargindiv1 col-md-6 pull-left"><span class="input-group-addon text-left"><div class="leftsidetextwidth">Date &amp; Time :</div></span>
                        <input type="text" class="form-control" value= "<%= hcsy.Created_On %>" > 
                      </div>
                      <div class="input-group bmargindiv1 col-md-6 pull-left"><span class="input-group-addon text-left"><div class="leftsidetextwidth">Name of Deceased :</div></span>
                        <input type="text" class="form-control" value= "<%= hcsy.Deceased_Name %>" > 
                      </div>
                      <div class="input-group bmargindiv1 col-md-6 pull-left"> <span class="input-group-addon text-left"><div class="leftsidetextwidth">Mobile No :</div></span>
                        <input type="text" class="form-control" value= "<%= hcsy.Mobile_No %>" > 
                      </div>
                      <div class="input-group bmargindiv1 col-md-6 pull-left"><span class="input-group-addon text-left"><div class="leftsidetextwidth">Beneficiary Name :</div></span>
                        <input type="text" class="form-control" value= "<%= hcsy.Beneficiary_Name %>" > 
                      </div>
                      <div class="input-group bmargindiv1 col-md-6 pull-left"> <span class="input-group-addon text-left"><div class="leftsidetextwidth">Occupation :</div></span>
                        <input type="text" class="form-control" value= "<%= hcsy.Occupation %>" > 
                      </div>
                      <div class="input-group bmargindiv1 col-md-12 pull-left"> <span class="input-group-addon text-left"><div class="leftsidetextwidth">Relation with Deceased :</div></span>
                        <input type="text" class="form-control" value= "<%= hcsy.Beneficiary_Rel_With_Decease %>" > 
                      </div>
                      <div class="input-group bmargindiv1 col-md-6 pull-left"> <span class="input-group-addon text-left"><div class="leftsidetextwidth">Address Line - I :</div></span>
                        <textarea name="versions comments"  class="form-control" rows="3"><%= hcsy.Beneficiary_Address1 %></textarea>
                      </div>
                      <div class="input-group bmargindiv1 col-md-6 pull-left"> <span class="input-group-addon text-left"><div class="leftsidetextwidth">Address Line - II :</div></span>
                        <textarea name="versions comments"  class="form-control" rows="3"><%= hcsy.Beneficiary_Address2 %></textarea>
                      </div>
                      <div class="input-group bmargindiv1 col-md-6 pull-left"> <span class="input-group-addon text-left"><div class="leftsidetextwidth">Village/City :</div></span>
                        <input type="text" class="form-control" value= "<%= hcsy.Beneficiary_Village %>" > 
                      </div>
                      <div class="input-group bmargindiv1 col-md-6 pull-left"> <span class="input-group-addon text-left"><div class="leftsidetextwidth">Block :</div></span>
                        <input type="text" class="form-control" value= "<%= hcsy.Beneficiary_Block %>" > 
                      </div>
                      <div class="input-group bmargindiv1 col-md-6 pull-left"> <span class="input-group-addon text-left"><div class="leftsidetextwidth">District :</div></span>
                        <input type="text" class="form-control" value= "<%= hcsy.Beneficiary_Dist %>" > 
                      </div>
                      <div class="input-group bmargindiv1 col-md-6 pull-left"> <span class="input-group-addon text-left"><div class="leftsidetextwidth">State :</div></span>
                        <input type="text" class="form-control" value= "<%= hcsy.Beneficiary_State %>" > 
                      </div>
                      <div class="input-group bmargindiv1 col-md-6 pull-left"> <span class="input-group-addon text-left"><div class="leftsidetextwidth">Country :</div></span>
                        <input type="text" class="form-control" value= "<%= hcsy.Beneficiary_Country %>" > 
                      </div>
                      <div class="input-group bmargindiv1 col-md-6 pull-left"> <span class="input-group-addon text-left"><div class="leftsidetextwidth">Police Station :</div></span>
                        <input type="text" class="form-control" value= "<%= hcsy.Beneficiary_PS %>" > 
                      </div>
                      <div class="clearfix"></div>
                </div>
            </div>
        </div>
        <div class="totalaligndiv">
            <div class="col-md-6" style="padding-left:0px;">
            <div class="block block-themed themed-asphalt">
                <div class="block-title"><h5>Annual Income From Sources</h5></div>
                    <div class="block-content full">
                        <div class="totalaligndiv">
                          <div class="input-group bmargindiv1 col-md-12 pull-left"><span class="input-group-addon text-left"><div class="leftsidetextwidth">BPL :</div></span>
                            <input type="text" class="form-control" value= "<%= hcsy.BPL %>" > 
                          </div>
                          <div class="input-group bmargindiv1 col-md-12 pull-left"><span class="input-group-addon text-left"><div class="leftsidetextwidth">Govt. Services :</div></span>
                            <input type="text" class="form-control" value= "<%= hcsy.Govt_Service %>" > 
                          </div>
                          <div class="input-group bmargindiv1 col-md-12 pull-left"><span class="input-group-addon text-left"><div class="leftsidetextwidth">Business :</div></span>
                            <input type="text" class="form-control" value= "<%= hcsy.Business %>" > 
                          </div>
                          <div class="input-group bmargindiv1 col-md-12 pull-left"> <span class="input-group-addon text-left"><div class="leftsidetextwidth">Land Property :</div></span>
                            <input type="text" class="form-control" value= "<%= hcsy.Land_Property %>" > 
                          </div>
                          <div class="input-group bmargindiv1 col-md-12 pull-left"> <span class="input-group-addon text-left"><div class="leftsidetextwidth">Others :</div></span>
                            <input type="text" class="form-control" value= "<%= hcsy.Others %>" >
                          </div>
                          <div class="input-group bmargindiv1 col-md-12 pull-left" style="height:55px;">
                          &nbsp; 
                          </div>
                          <div class="clearfix"></div>
                    </div>
                    </div>
            </div>
            </div>
            <div class="col-md-6" style="padding-right:0px;">
              <div class="block block-themed themed-asphalt">
                    <div class="block-title"><h5>Application Details</h5></div>
                    <div class="block-content full">
                        <div class="totalaligndiv">
                          <div class="input-group bmargindiv1 col-md-12 pull-left"><span class="input-group-addon text-left"><div class="leftsidetextwidth">Select Purpose :</div></span>
                            <input type="text" class="form-control" value= "<%= hcsy.Brahmin %>" > 
                          </div>
                          <div class="input-group bmargindiv1 col-md-12 pull-left"><span class="input-group-addon text-left"><div class="leftsidetextwidth">Amount Required :</div></span>
                            <input type="text" class="form-control" value= "<%= hcsy.Amout_Required %>" > 
                          </div>
                          <div>Has he/she received any assistance earlier from this fund</div>
                          <div class="input-group bmargindiv1 col-md-12 pull-left">
                          <span class="input-group-addon text-left"><div class="leftsidetextwidth">Status :</div></span>
                            <input type="text" class="form-control" value= "<%= hcsy.Received_Fund_Earlier %>" > 
                          </div>
                          <div class="input-group bmargindiv1 col-md-12 pull-left"> <span class="input-group-addon text-left"><div class="leftsidetextwidth">Prev. Receipt No. :</div></span>
                            <input type="text" class="form-control" value= "<%= hcsy.Prev_Receipt_No %>" > 
                          </div>
                          <div class="input-group bmargindiv1 col-md-12 pull-left"> <span class="input-group-addon text-left"><div class="leftsidetextwidth">Amount Received :</div></span>
                            <input type="text" class="form-control" value= "<%= hcsy.Prev_Amount_Received %>" > 
                          </div>
                          <div class="input-group bmargindiv1 col-md-12 pull-left"> <span class="input-group-addon text-left"><div class="leftsidetextwidth">Date of Received :</div></span>
                            <input type="text" class="form-control" value= "<%= hcsy.Prev_Date_Received %>" > 
                          </div>
                          <div class="clearfix"></div>
                    </div>
                    </div>
                </div>
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="tpaddingdiv1">
            <div class="col-md-4">
                <div class="text-center bpaddingdiv1"><img src="<%= hcsy.D_Photo %>" border="0" name="signature" height="140" class="borderblackdiv"></div>
                <div class="fontweightbolddiv fontssizediv3 text-center bpaddingdiv1">Deceased Photo</div>
            </div>
            <div class="col-md-4">
                <div class="text-center bpaddingdiv1"><img src="<%= hcsy.B_Photo %>" border="0" name="signature" height="140" class="borderblackdiv"></div>
                <div class="fontweightbolddiv fontssizediv3 bpaddingdiv1 text-center">Donor Photo</div>
            </div>
            <div class="col-md-4">
                <div class="text-center bpaddingdiv1"><img src="/assets/signaturetwo.jpg" border="0" name="signature" height="140" class="borderblackdiv"></div>
                <div class="fontweightbolddiv fontssizediv3 bpaddingdiv1 text-center">Donor Thumb</div>
            </div>
            <div class="clearfix"></div>
      </div>
    </div>

scan_report.html.erb

<%= render partial: "hcsy_output_table", locals: {hcsy: @hcsy} %>

我需要_hcsy_output_table.html.erb应该在形式之后在相同的主页上呈现并且它应该在没有重新加载页面的情况下意味着当用户将提交表单将提交的收据号码时突然显示所有值。请帮我解决这个问题。

0 个答案:

没有答案