我想使用Rails 3将数组中的值分配给文本字段。我有一个表格,如下所示。
paymenttable.html.erb:
<table class="table table-bordered">
<colgroup>
<col class="col-md-1 col-sm-1">
<col class="col-md-1 col-sm-1">
<col class="col-md-3 col-sm-3">
<col class="col-md-3 col-sm-3">
<col class="col-md-4 col-sm-4">
</colgroup>
<thead>
<tr>
<th class="text-center"><input type="checkbox"></th>
<th class="text-center">Sl. No</th>
<th class="text-center">Date</th>
<th class="text-center">Receipt No.</th>
<th class="text-center">Amount</th>
</tr>
</thead>
<tbody>
<% @result.each do |r| %>
<tr>
<%= hidden_field_tag :r_value,params[:r_value]=r %>
<th class="text-center"><%= check_box_tag :check_value, 1, :id => "checkbox1-1" %></th>
<td class="text-center"><%= r.id %></td>
<td class="text-center"><%= r.c_date %></td>
<td class="text-center"><%= r.Receipt_No %></td>
<td class="text-center"><i class="fa fa-rupee"></i><%= r.v_amount %></td>
</tr>
<% end %>
</tbody>
</table>
payment_controller.rb:
class PaymentsController < ApplicationController
def payment
@payment=Vendor.new
@add_payment=AddPayment.new
respond_to do |format|
format.html
format.js
end
end
def check_type
if params[:commit]=="submit"
@vendor_type = PaymentVendor.where(:v_name => params[:v_name]).map{|v|[v.v_catagory ,v.Receipt_No]}
#@vendor_type = PaymentVendor.where(:v_name => params[:v_name]).pluck(:v_catagory)
@output=[]
#@result=[]
@r_no=[]
@vendor_type.each do |i|
if i.first == params[:payment][:s_catagory]
@output << i[1]
end
end
@output.each do |o|
@r_no << o
@result = PaymentVendor.where(:Receipt_No => @r_no,:v_catagory => params[:payment][:s_catagory],:v_name => params[:v_name] )
end
#puts "#{val} => #{index}"
#puts output1[index]
#@result = PaymentVendor.where(:Receipt_No => @output[index],:v_catagory => params[:payment][:s_catagory],:v_name => params[:v_name] )
else
@v_name=Vendor.where(:s_catagory => params[:payment][:s_catagory] ).pluck(:v_name)
end
end
def add_payment
if params[:commit]
params[:check_value] == '1' ? remember : forget
#if params[:add_payment][:p_catagory]=="Cash"
#@abc=true
#@add_payment=AddPayment.create(:p_catagory => params[:add_payment][:p_catagory],:paid_amount => params[:check_value][:value].v_amount,:total_claim => 1 )
#else
#@abc=true
#@add_payment=AddPayment.create(:p_catagory => params[:add_payment][:p_catagory],:paid_amount => params[:value].v_amount,:total_claim => 1,:chk_details => params[:chk_details],:chk_no => params[:chk_no] )
#end
else
if params[:add_payment][:p_catagory]=="Cheque"
@chk=true
end
end
end
private
def remember
@r_value=[]
@r_value << params[:r_value]
@r_value.each do |value|
#@add_payment=AddPayment.create(:p_catagory => params[:add_payment][:p_catagory],:paid_amount => value.v_amount,:total_claim => 1,:chk_details => params[:chk_details],:chk_no => params[:chk_no] )
@abc=true
end
end
end
我已按照表格中给出的上述方式进行了分配。但是当我签入生成的html时,这个隐藏字段的输出为<input id="r_value" name="r_value" type="hidden" value="#<PaymentVendor:0x2c0fd90>">
。我在这里找不到任何值。实际上我需要{{1在每次重复循环时,将所有v_amount值存储在array中的隐藏字段中。请帮助我。