使用Rails 3将文本字段值转换为控制器操作

时间:2015-04-24 06:27:58

标签: ruby ruby-on-rails-3

我想使用rails 3在控制器操作中获取文本字段值。此文本字段值是正常值,而不在rails表单中。检查我的下面的代码。

  

家/家/ _good.html.erb:

<div class="block-content" style="display:none;">
        <div class="timeline-container">
              <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= "<%= @sdf.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= "<%= @sdf.Created_On %>" > 
              </div>
              <div class="input-group bmargindiv1 col-md-6 pull-left"><span class="input-group-addon text-left"><div class="leftsidetextwidth">Deceased Name :</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">Donor Name :</div></span>
                <input type="text" class="form-control" value= "<%= @sdf.Doner_Name %>" > 
              </div>
              <div class="input-group bmargindiv1 col-md-12 pull-left"> <span class="input-group-addon text-left"><div class="leftsidetextwidth">Amount :</div></span>
                <input type="text" class="form-control" value= "<%= @good.Amount %>">
              </div>
              <div class="clearfix"></div>
        </div>
       <div class="block block-themed themed-asphalt">
      <div class="block-title"><h5>Office Use</h5></div>
            <div class="block-content full">
               <%= form_for :vendor,:url => {:action =>"payment" } do |f| %>
                    <div class="totalaligndiv">
                      <div class="input-group bmargindiv1 col-md-6" style="margin:auto; float:none;"><span class="input-group-addon text-left"><div class="leftsidetextwidth">Select Vendor :</div></span>
                      <%= f.select(:v_name,options_for_select(Vendor.where(s_catagory:  "Puja Samagree").pluck(:v_name),selected: "Select vender name"),{},{:class => "form-control"}) %>
                      </div>
                      <div class="clearfix"></div>
                      <div class="tbpaddingdiv1 text-center">
                        <%= f.submit "Add to Payment",:class => "btn btn-success" %>
                      </div>
                      <div class="clearfix"></div>
                </div>
                <% end %>
            </div>
        </div>
    </div>
    <!--end_2nd_total_div-->
  

控制器/ homes_controller.rb:

class HomesController < ApplicationController
    def home
        @sdf=TSdf.new
        respond_to do |format|
          format.html
          format.js
        end
    end
    def scan_report
           if @sdf=TSdf.find_by_Receipt_No(params[:sdf][:Receipt_No])
                @hcsy=THcsy.find_by_Sdp_Id(@sdf.Sdp_Id)
                @hcsy_deatils=THcsyDetails.find_by_HCSY_ID(@hcsy.id)
                @woods=THcsyFundTypeMaster.find_by_Fund_Type_Code(1)
                @burn=THcsyFundTypeMaster.find_by_Fund_Type_Code(2)
                @good=THcsyFundTypeMaster.find_by_Fund_Type_Code(3)
                @swd=THcsyFundTypeMaster.find_by_Fund_Type_Code(5)
                @photo=THcsyFundTypeMaster.find_by_Fund_Type_Code(6)
                @vendor=Vendor.new
                flash[:notice]=" number matched"
            else
                splitted = params[:sdf][:Receipt_No].split('/')
                receipt = splitted[0]
                table_id = splitted[1]
                @sdfs=TSdf.find_by_Receipt_No(receipt)
                if @sdfs
                    @hcsys=THcsy.find_by_Sdp_Id(@sdfs.Sdp_Id)
                    @fund_details=THcsyFundTypeMaster.find_by_Fund_Type_Code(table_id)
                else
                    flash[:notice]="Scan number not found"
                end
            end
    end
    def payment
        @vendor=AddToPaymentVendor.create()
    end
end

我想在付款操作中保存创建方法中上面视图页面中显示的Receipt_No。请帮我解决此问题。

2 个答案:

答案 0 :(得分:1)

将Receipt_No作为隐藏字段添加到表单http://apidock.com/rails/ActionView/Helpers/FormHelper/hidden_field,其值为@ sdf.Receipt_No

答案 1 :(得分:0)

在homes / home / _good.html.erb:

sum(amount * price * 1) -- if discount and client discount are both 0

在controller / homes_controller.rb中:

    <%= form_for :vendor,:url => {:action =>"payment" } do |f| %>
      <div class="totalaligndiv">
        <%= hidden_field_tag 'receipt_no', @sdf.Receipt_No %>
      </div>
    <% end %>

其中column_name表示要在AddToPaymentVendor模型中保存收货的列