I want to display some array of data in table using Rails 3. suppose I have the below array of data.
#vendor_type=["SWD", "GOODS","SWD"]
My database structure is given below.
table- Payment_vendors:
id Receipt_No type v_amount v_date c_date v_name v_status
7 150325005 SWD 60.00 2015-04-15 2015-04-28 Deepak No
8 150325006 GOODS 1195.00 2015-04-15 2015-04-28 Deepak No
9 150325007 SWD 60.00 2015-04-15 2015-04-29 Deepak No
Actually My requirement is when #vendor_type==SWD,it will retrieve all Receipt_no corresponding to that "SWD".According to the Receipt_No corresponding row data will fetch and append in the below table.
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>
<tr>
<th class="text-center"><input type="checkbox" id="checkbox1-1" name="checkbox1-1"></th>
<td class="text-center"></td>
<td class="text-center"></td>
<td class="text-center"></td>
<td class="text-center"><i class="fa fa-rupee"></i></td>
</tr>
</tbody>
</table>
My controller file is given 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]).pluck(:type )
##vendor_type=PaymentVendor.pluck_all(PaymentVendor.where(:v_name => params[:v_name]),:type ,:Receipt_No)
else
#v_name=Vendor.where(:s_catagory => params[:payment][:s_catagory] ).pluck(:v_name)
end
end
end
Please help me to resolve this issue.
I can only give a best guess at what you want but I think what you are trying to ask for is this:
1) Change this line in check_type method in PaymentsController:
#vendor_type=PaymentVendor.where(:v_name => params[:v_name])
this gets rid of the .pluck method and returns an array of PaymentVendor objects instead of just the column :type.
Now in your ERB file you need a looping structure that will create rows in the table body for each item in the #vendor_type data structure:
...
</thead>
<tbody>
<% #vendor_type.each do |vt| %>
<tr>
<td class="text-center"><input type="checkbox" id="checkbox1-1" name="checkbox1-1"></th>
<td class="text-center">????? what column does "Sl. No" refer to??? </td>
<td class="text-center"><%= vt.v_date %></td>
<td class="text-center"><%= vt.receipt_no %></td>
<td class="text-center"><i class="fa fa-rupee"><%= vt.v_amount %></i></td>
</tr>
<% end %>
</tbody>
</table>
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 :)
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.
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.
I have a check box. I need when this check box is checked then the controller action will get all the related data, if it is not checked it will not.
<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.v_amount %>
<tr>
<th class="text-center"><%= check_box_tag "deatils[]" ,r.v_amount,{} ,:id => r.id %></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>
Please help me to resolve this issue.
Add class 'related_data' to the checkbox field
<%= check_box_tag "deatils[]" ,r.v_amount,{} ,:id => r.id,class: 'related_data' %>
Then write a coffee like this:
jQuery(".related_data").live 'change', ->
jQuery.ajax '/controller/action_to_get_data',
type: 'POST'
I hope you get an idea to solve your problem.