我的表中有一个隐藏字段。我需要在rails中访问控制器的所有数组值。检查我的下表。
paymentresult.html.erb:
<%= form_for :add_payment,:url => {:action => 'add_payment' },remote: true do |f| %>
<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| %>
<%= hidden_field_tag 'infos[]', r %>
<tr>
<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>
<%= f.submit "Add to payment",:class => "btn btn-success",:id => "switch_car11" %>
<% end %>
payment_controller.rb
class PaymentsController < ApplicationController
def add_payment
if params[:commit]
params[:check_value] == '1' ? remember : forget
else
if params[:add_payment][:p_catagory]=="Cheque"
@chk=true
end
end
end
private
def remember
@reslt=params[:infos]
@add_payment=AddPayment.create(:p_catagory => params[:add_payment][:p_catagory],:paid_amount => "here i want to add the table's v_amount value",:total_claim => 1 )
end
end
add_payment.rb:
class AddPayment < ActiveRecord::Base
attr_accessible :chk_details, :chk_no, :p_catagory, :paid_amount, :total_claim
end
我需要当用户点击提交按钮然后所有数组值(ie- @结果)应该获取add_payment方法。我尝试使用隐藏字段但无法获取所有数据。这是我的要求是在提交表单之后全部@result
的值应该提取到控制器方法中,以便我可以在DB中保存一些值。