I have a hidden field in my table.I need to access all array value into controller's action method in rails.Check my below table.
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
I need when user will click on submit button then all array value(i.e-#result) should fetch to add_payment method.I tried by using hidden field but failed to fetch all data.Here my requirement is after submitting the form all value of #resultshould fetch into controller method so that i can save some value from this in DB.
Related
I am using will_paginate gem for searching data from table as per two date.Here my requirement is If no search data is found there should be one notification to user i.e-"No record found in between these two date.".Mu code files are given below.
view_report.html.erb:
<div class="col-md-4 col-md-offset-1">
<div class="text-left">
To
</div>
<div class="input-group bmargindiv1 date" id='datepicker1' data-date="2015-05-01" data-date-format="yyyy-mm-dd">
<%= text_field_tag :search1, params[:search1], :class => "form-control" %>
<span class="add-on input-group-addon"><i class="fa fa-calendar"></i></span>
</div>
<script type="text/javascript">
$('#datepicker1').datepicker({
format: "yyyy-mm-dd"
});
</script>
</div>
<%= submit_tag "Search",:class => "btn btn-info btn-lg" %>
<div class="clearfix"></div>
<% end %>
</div>
<!--1st_total_div-->
<!--1st_total_div-->
<div class="block-content">
<div class="table-responsive">
<table class="table table-bordered">
<colgroup>
<col class="col-new-md-1">
<col class="col-new-md-1">
<col class="col-new-md-1">
<col class="col-new-md-1">
<col class="col-new-md-1">
<col class="col-new-md-1">
<col class="col-new-md-1">
<col class="col-new-md-1">
<col class="col-new-md-1">
<col class="col-new-md-1">
<col class="col-new-md-1">
<col class="col-new-md-1">
<col class="col-new-md-1">
<col class="col-new-md-1">
<col class="col-new-md-1">
<col class="col-new-md-1">
</colgroup>
<thead>
<tr>
<th class="text-center">Sl. No</th>
<th class="text-center">Receipt<br>Number</th>
<th class="text-center">Date</th>
<th class="text-center">Deceased<br>Name</th>
<th class="text-center">Doner<br>Name</th>
<th class="text-center">Doner<br>Mobile No</th>
<th class="text-center">Doner's<br>Relationship</th>
<th class="text-center">Donation<br>Amount</th>
<th class="text-center">Date of<br>death</th>
<th class="text-center">HCSY<br>Status</th>
<th class="text-center">Brahmin</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
<% #sdf.each do |sdf| %>
<% #count=#count+1 %>
<tr>
<td class="text-center"><%= #count %></td>
<td class="text-center"><%= sdf.Receipt_No %></td>
<td class="text-center"><%= sdf.Created_On %></td>
<td class="text-center"><%= sdf.Deceased_Name %></td>
<td class="text-center"><%= sdf.Doner_Name %></td>
<td class="text-center"><%= sdf.Doner_MobileNo %></td>
<td class="text-center"><%= sdf.Doner_Relationship_Other %></td>
<td class="text-center"><%= sdf.Donation_Amount %></td>
<td class="text-center"><%= sdf.Date_Of_Death %></td>
<td class="text-center"><%= sdf.HCSY_Status %></td>
<td class="text-center"><%= sdf.Brahmin %></td>
<td class="text-center">
<div class="btn-group">
<a href="/homes/home/?receipt_no=<%= sdf.Receipt_No %>" data-toggle="tooltip" title="" class="btn btn-xs btn-success" data-original-title="View">
<i class="fa fa-eye"></i>
</a>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= will_paginate #sdf %>
</div>
</div>
<!--end_1st_total_div-->
<!--end_1st_total_div-->
</div>
reports_controller.rb:
class ReportsController < ApplicationController
helper_method :sort_column, :sort_direction
def view_report
#count=0
#sdf =TSdf.all
#sdf = TSdf.search(params[:search],params[:search1]).order(sort_column + ' ' + sort_direction).paginate(:per_page => 10, :page => params[:page])
end
def sort_column
TSdf.column_names.include?(params[:sort]) ? params[:sort] : "Created_On"
end
def sort_direction
%w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"
end
end
t_sdf.rb:
class TSdf < ActiveRecord::Base
# attr_accessible :title, :body
self.table_name = 'T_SDF'
def self.search(search,search1)
if search && search1
#where('Created_On LIKE ?', "%#{search}%")
where("Created_On >= ? AND Created_On <= ?", search, search1 )
else
scoped
end
end
end
Please help me to add this notification as per the requirement.
Try this:
<% if #sdf.blank? %>
<p>No record found in between these two date.</p>
<% else %>
<table class="table table-bordered">
....
<thead>
....
</thead>
<tbody>
<% #sdf.each do |sdf| %>
....
<% end %>
</tbody>
</table>
<%= will_paginate #sdf %>
<% end %>
I have a check-box inside a form.I need if user will checked this check-box suddenly the action will execute and it will check the check-box status whether it is checked or not using Rails 3.My form is given below.
paym.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| %>
<tr>
<th class="text-center"><%= check_box_tag :check_value,nil,: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>
<% end %>
paym_controller.rb:
class PaymentsController < ApplicationController
def add_payment
end
end
Here i have a table with some value .I also need when user will checked that box 1-It will check whether check box is checked or not,2-If checked then it will get all table value corresponding to that check-box.Please help me.
<%= check_box_tag :check_value,nil,:id => "checkbox1-1" %>
You had pass nil value instead pass the object r like:
<%= check_box_tag :check_value, :value => r, :id => "checkbox1-1" %>
Now using jquery you can check if checkbox is checked then retrieve it's value. In form of value you will get particular object r and from that you can fetch your required data.
I hope this may helps you :)
Hi i am getting the following error when trying to render a table using Rails 3.
Error:
ActionView::Template::Error (undefined local variable or method `result' for #<#
<Class:0x3460410>:0x2af4d10>):
I am explaining my code snippets below.
payments_controller.rb:
class PaymentsController < ApplicationController
def payment
#payment=Vendor.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])
puts "Value of local variable is #{result}"
}
else
#v_name=Vendor.where(:s_catagory => params[:payment][:s_catagory] ).pluck(:v_name)
end
end
end
check_type.js.erb:
<% if #v_name %>
$("#div_select").css("display", "block");
$("#name-option").html("<%= escape_javascript (render 'nameoption' ) %>");
$("#name-option").slideDown(350);
<% end %>
<% if #vendor_type %>
console.log('hello')
$(".flash-message").html('<%= escape_javascript flash[:notice] %>');
$("#paymentdetail").css("display", "block");
$("#paymentoption").html("<%= escape_javascript (render 'paymentdetails' ) %>");
$("#paymentoption").slideDown(350);
<% end %>
_paymentdetails.html.erb:
<div><%= #vendor_type %></div>
<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>
This table will render on the payment.html.erb page.I got success to render blank table but i need to show the value within result variable on this table.Please help me to resolve this error.
If you want to make result accessible in view, you should make it instance variable (#result).
result is locally defined in check_type its not accessible in view.
change it to #result in view and controller.
I want to add oninput event in rails form using ajax call.I added it but its not working.I also want when input field will get the data the form will submit and result will come in the same page without reloading the page.I am explaining my code below.
homes/home.html.erb
<%= form_for :sdf ,:url => {:action => "scan_report" },remote: true do |f| %>
<% if params[:receipt_no] %>
<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", :value => params[:receipt_no],oninput => "this.form.submit();" %>
</div>
<% else %>
<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" %>
</div>
<% end %>
<% end %>
The above input field will get value when user will click on view action of table which is given below.
reports/view_report.html.erb
<div class="block-content">
<div class="table-responsive">
<table class="table table-bordered">
<colgroup>
<col class="col-md-1 col-sm-1">
<col class="col-md-2 col-sm-2">
<col class="col-md-3 col-sm-3">
<col class="col-md-3 col-sm-3">
<col class="col-md-1 col-sm-1">
<col class="col-md-1 col-sm-1">
<col class="col-md-1 col-sm-1">
</colgroup>
<thead>
<tr>
<th class="text-center">Sl. No</th>
<th class="text-center">Receipt Number</th>
<th class="text-center">Date</th>
<th class="text-center">Deceased Name</th>
<th class="text-center">Deceased Adress</th>
<th class="text-center">Doner Name</th>
<th class="text-center">Doner Adress</th>
<th class="text-center">Doner Mobile No</th>
<th class="text-center">Doner's Relationship</th>
<th class="text-center">Donation Amount</th>
<th class="text-center">Date of death</th>
<th class="text-center">HCSY Status</th>
<th class="text-center">Deceased photo</th>
<th class="text-center">Doner photo</th>
<th class="text-center">Brahmin</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
<% #sdf.each do |sdf| %>
<tr>
<td class="text-center"><%= sdf.Sdp_Id %></td>
<td class="text-center"><%= sdf.Receipt_No %></td>
<td class="text-center"><%= sdf.Created_On %></td>
<td class="text-center"><%= sdf.Deceased_Name %></td>
<td class="text-center"><%= sdf.Deceased_Address1 %></td>
<td class="text-center"><%= sdf.Doner_Name %></td>
<td class="text-center"><%= sdf.Doner_Address1 %></td>
<td class="text-center"><%= sdf.Doner_MobileNo %></td>
<td class="text-center"><%= sdf.Doner_Relationship_Other %></td>
<td class="text-center"><%= sdf.Donation_Amount %></td>
<td class="text-center"><%= sdf.Date_Of_Death %></td>
<td class="text-center"><%= sdf.HCSY_Status %></td>
<td class="text-center"><%= image_tag(sdf.Photo,:width => 50,:height => 50) %></td>
<td class="text-center"><%= image_tag(sdf.Doner_Photo,:width => 50,:height => 50) %></td>
<td class="text-center"><%= sdf.Brahmin %></td>
<td class="text-center">
<div class="btn-group">
<a href="/homes/home/?receipt_no=<%= sdf.Receipt_No %>" data-toggle="tooltip" title="" class="btn btn-xs btn-success" data-original-title="View">
<i class="fa fa-eye"></i>
</a>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= will_paginate #sdf %>
</div>
</div>
My other files are given below.
controller/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)
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
end
scan_report.js.erb
$("#whole-div1").css("display", "block");
$("#whole-div").css("display", "block");
$("#whole-div3").css("display", "block");
$("#whole-div4").css("display", "block");
$("#whole-div5").css("display", "block");
$("#whole-div6").css("display", "block");
$("#whole-div8").css("display", "block");
$(".flash-message").html('<%= escape_javascript flash[:notice] %>');
$("#sdf-puri").html("<%= escape_javascript (render 'sdf_output_table' ) %>");
$("#sdf-puri").slideDown(350);
$("#hcsy-puri").html("<%= escape_javascript (render 'hcsy_output_table' ) %>");
$("#hcsy-puri").slideDown(350);
$("#good-puri").html("<%= escape_javascript (render 'goods' ) %>");
$("#good-puri").slideDown(350);
$("#swd-puri").html("<%= escape_javascript (render 'swd' ) %>");
$("#swd-puri").slideDown(350);
$("#burn-puri").html("<%= escape_javascript (render 'burning' ) %>");
$("#burn-puri").slideDown(350);
$("#wood-puri").html("<%= escape_javascript (render 'woods' ) %>");
$("#wood-puri").slideDown(350);
$("#photo-puri").html("<%= escape_javascript (render 'photo' ) %>");
$("#photo-puri").slideDown(350);
Please help me to add this type of feature and its very important that result should come the same page without reloading the page.
I have a table with data including one check-box in each row.I need when user will click on check box then the corresponding row values will retrieve using Rails.My table is given below.
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"><%= check_box_tag :check_value,:value => r %></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]
else
if params[:add_payment][:p_catagory]=="Cheque"
end
end
end
end
When check box will checked the row all row value will fetch to controller action assign to a variable.Similarly for multiple check box if at a time all check box will select all row values corresponding to each check box will assign to a variable.Please help me to resolve this problem.