suppose i have multiple rows in a table.Each table has one,one check box.When user will checked one check box his corresponding row value will saved in db and when user will multiple check box their corresponding row value will saved in db.
The followings are my below code.
payment.html.erb:
<div class="tbpaddingdiv2">
<%= form_for :payment,:url => {:action => "check_type" },remote: true do |f| %>
<div class="totalaligndiv">
<div class="input-group bmargindiv1 col-md-6 pull-left"><span class="input-group-addon text-left"><div class="leftsidetextwidth">Type :</div></span>
<%= f.select(:s_catagory,options_for_select([['Wood','Woods'],['Puja Samagree','GOODS'],['Sweeper','SWD'],['Photo Grapher','PHOTO'],['Burning Assistant','BURNING'],['BRAHMIN','BRAHMIN']],selected: "Type"),{},{:class => 'form-control',:onchange => ("$('#switch_car').submit()")}) %>
</div>
<div id="div_select" style="display:none">
<div class="input-group bmargindiv1 col-md-6 pull-left" ><span class="input-group-addon text-left" ><div class="leftsidetextwidth">Select Vendor :</div></span>
<div id="name-option">
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="tbpaddingdiv1 text-center">
<%= f.submit "submit",:class => "btn btn-success",:id => "switch_car" %>
</div>
</div>
<% end %>
</div>
<div class="bpaddingdiv2" id= "paymentdetail" style="display:none;">
<div class="table-responsive" id="paymentoption">
</div>
<div class="totalaligndiv">
<%= form_for :add_payment,:url => {:action => 'add_payment' },remote: true do |f| %>
<div class="input-group bmargindiv1 col-md-6" style="margin:auto auto 10px auto; float:none;"><span class="input-group-addon text-left"><div class="leftsidetextwidth">Payment Type :</div></span>
<%= f.select(:p_catagory,options_for_select([['Cash','Cash'],['Cheque','Cheque']],selected: "Type"),{},{:class => 'form-control',:onchange => ("$('#switch_car11').submit()")}) %>
</div>
<div class="clearfix"></div>
<div class="totalaligndiv" id="payment-main" style="display:none;" >
<div id="payment-child" >
</div>
</div>
<div class="tbpaddingdiv1 text-center">
<%= f.submit "Add to payment",:class => "btn btn-success",:id => "switch_car11" %>
</div>
<div class="clearfix"></div>
<% end %>
</div>
_paymentdetails.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>
<th class="text-center"><input type="checkbox" id="checkbox1-1" name="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=[]
@vendor_type.each do |i|
if i.first == params[:payment][:s_catagory]
output << i[1]
end
end
output.each_with_index{|val, index|
#puts "#{val} => #{index}"
#puts output1[index]
@result << PaymentVendor.find_by_Receipt_No(output[index])
}
else
@v_name=Vendor.where(:s_catagory => params[:payment][:s_catagory] ).pluck(:v_name)
end
end
def add_payment
if params[:commit]
@add_payment=AddPayment.new(params[:add_payment])
else
if params[:add_payment][:p_catagory]=="Cheque"
end
end
end
end
As you can see all are ajax call that table is render on the payment.html.erb
page.When user will checked the check box and submit the formall data belongs to that check box will saved in db through add_payment action.Please help me.
Aucun commentaire:
Enregistrer un commentaire