Search form don't update table in RoR - ruby-on-rails

I'm trying to write a filter for the table. Here is the code:
.../models/message.rb
Class Message < ActiveRecord::Base
include Filterable
belongs_to :user
default_scope -> { order('created_at DESC') }
validates :user_id, presence: true
validates :content, presence: { message: "Выберите файл послания для загрузки!" }, file_size: { less_than_or_equal_to: 20.megabytes }
validates :fromdate, presence: true
validates :tilldate, presence: true
mount_uploader :content, ContentUploader
scope :id, -> (id) {where id: id }
scope :tariff, -> (tariff) { where tariff: tariff }
scope :status, -> (status) { where("status like ?", "#{status}%")}
end
.../controllers/concerns/filterable.rb
module Filterable
extend ActiveSupport::Concern
module ClassMethods
def filter(filtering_params)
results = self.where(nil)
filtering_params.each do |key, value|
results = results.public_send(key, value) if value.present?
end
results
end
end
end
.../controllers/messages_controller.rb
...
def index
#messages = Message.filter(params.slice(:id, :tariff, :status)).paginate(page: params[:page], :per_page => 10)
end
...
.../views/messages/index.html.erb
...
<table class="table table-bordered">
<thead>
<tr>
<th>Клиент</th>
<th>№</th>
<th>Дата</th>
<th>Послание</th>
<th>Тариф</th>
<th>Показ с</th>
<th>до</th>
<th>Стоимость, р.</th>
<th>Статус</th>
<% if current_user.admin? %>
<th>Модератор</th>
<% end %>
</tr>
</thead>
<tbody>
<tr>
<%= form_tag messages_path, method: "get" do %>
<td><%= text_field_tag "client" %></td>
<td><%= text_field_tag "id", nil, size: 1 %></td>
<td></td>
<td><%= submit_tag "Выбрать" %><br><br><%= button_tag "Очистить" %></td>
<td><%= select_tag "tariff", options_for_select(["", "1. Вечер", "2. Весь день", "1001. ВЕЧЕР БЕСПЛАТНО", "1002. ДЕНЬ БЕСПЛАТНО"]), {} %></td>
<td></td>
<td></td>
<td></td>
<td><%= select_tag "status", options_for_select(["", "В обработке", "Исполняется", "Отклонена", "Выполнена"]), {} %></td>
<td></td>
<% end %>
</tr>
<%= render #messages %>
</tbody>
</table>
</div>
...
.../views/messages/_message.html.erb
...
<% case message.status
when "В обработке"
#messagecolor="warning"
when "Исполняется"
#messagecolor="success"
when "Выполнена"
#messagecolor="info"
when /Отклонена.*/
#messagecolor="danger"
end
unless message.moderator.nil?
#moderator = User.find(message.moderator).name
end
%>
<tr class=<%= #messagecolor %> data-message_id="<%= message.id %>">
<% if current_user.admin? || current_user.role == "Модератор" %>
<td><%= message.user.name %></td>
<% end %>
<td><%= message.id %></td>
<td><%= message.created_at.strftime("%d/%m/%Y %T %z") %></td>
<td><img src="<%= message.content_url(:thumb) %>" data-toggle="modal" data-target="#myModal" data-content="<%= message.content_url%>"></td>
<td><%= message.tariff %></td>
<td><%= message.fromdate.strftime("%d/%m/%Y") %></td>
<td><%= message.tilldate.strftime("%d/%m/%Y") %></td>
<td><%= message.cost %></td>
<td class="status">
<%= message.status %>
<% if (current_user.admin? || current_user.role == "Модератор") && message.status == "В обработке" %>
<br>
<div class="btn-group">
<button type="button" class="btn btn-success" data-status="Исполняется" data-message_id="<%= message.id %>">Принять</button>
<button type="button" class="btn btn-danger" data-status="Отклонена" data-message_id="<%= message.id %>">Отклонить</button>
</div>
<% end %>
<% if (current_user.admin? || current_user.role == "Модератор") && message.status == "Исполняется" %>
<br>
<%= link_to "Изменить", edit_message_path(message.id), :class => "btn btn-info" %>
<% end %>
</td>
<% if current_user.admin? %>
<td class="moderator">
<%= #moderator %><br>
<%= message.updated_at.strftime("%d/%m/%Y %T %z")%>
</td>
<% end %>
</tr>
...
The filter only works after the page is refreshed. It is worth to get back to the page through the menu - the form button does not work, update by F5 - it works. Why?
I will also be grateful if you tell me how to save the selected filter values ​​in the fields after it is applied.

I found the answer to my main question: it need to include the entire table into the form in .../views/messages/index.html.erb
...
<%= form_tag messages_path, method: "get" do %>
<table class="table table-bordered">
<thead>
<tr>
<th>Клиент</th>
<th>№</th>
<th>Дата</th>
<th>Послание</th>
<th>Тариф</th>
<th>Показ с</th>
<th>до</th>
<th>Стоимость, р.</th>
<th>Статус</th>
<% if current_user.admin? %>
<th>Модератор</th>
<% end %>
</tr>
</thead>
<tbody>
<tr>
<td><%= text_field_tag "client" %></td>
<td><%= text_field_tag "id", nil, size: 1 %></td>
<td></td>
<td><%= submit_tag "Выбрать" %><br><br><%= button_tag "Очистить" %></td>
<td><%= select_tag "tariff", options_for_select(["", "1. Вечер", "2. Весь день", "1001. ВЕЧЕР БЕСПЛАТНО", "1002. ДЕНЬ БЕСПЛАТНО"]), {} %></td>
<td></td>
<td></td>
<td></td>
<td><%= select_tag "status", options_for_select(["", "В обработке", "Исполняется", "Отклонена", "Выполнена"]), {} %></td>
<td></td>
</tr>
<%= render #messages %>
</tbody>
</table>
<% end %>
</div>
...
And now it works correctly.

Related

ror How can i order by has many value

How can I order by has-many value
I want to do something like #cases = #user.cases.order_by(step.name="shipped" desc)
I have cases table and I want if the case.step.name = "Shipped" to be at the end of the table
I have case model
has_many :steptations, dependent: :destroy
has_many :steps, through: :steptations
accepts_nested_attributes_for :steps
and step model
has_many :steptations,dependent: :destroy
has_many :cases, through: :steptations
Here is my cases controller
def index
#cases = #user.cases.all
end
Here is my case.html
<% #cases.each do |item| %><tr>
<td ><%= link_to case_path(item) do %><%= item.number %><% end %></td>
<% if item.steptations.present? %>
<% item.steptations.where(:status=>true).each do |t| %>
<% if t.step&.id == 13 %>
<td class= 'fa fa-circle red' ></td>
<% elsif item.finished == true && t.step&.name == "Shipped"%>
<td class= 'fa fa-circle red' ></td>
<% elsif item.finished == true %>
<td class= 'fa fa-circle dark'></td>
<% else %>
<td class= 'fa fa-circle green'></td>
<% end %>
<% end %>
<% else %>
<td>0</td>
<% end %>
<td> <%= link_to case_path(item) do %><%= item.pt_first_name.capitalize %> <%= item.pt_last_name.capitalize %><% end %></td>
<td><%=link_to item.user.full_name,doctor_path(item.user)%></td>
<td> <%= item.date_received.strftime("%b-%-d-%-y") %></td>
<td> <%= item.due_date.strftime("%b-%-d-%-y") %></td>
<td><%= item.shade %></td>
<td><%= item.mould %></td>
<td><%= item.upper_lower %></td>
<% if item.steptations.present? %>
<% item.steptations.where(:status=>true).each do |t| %>
<% if t.step&.name == "Conversion" %>
<td class="red"><%= t.step&.name%></td>
<% else %>
<td><%= t.step&.name%> </td>
<% end %>
<% end %>
<% else %>
<td>0</td>
<% end %>
</td>
</tr>
<% end %></tbody>
</table><br>
What you're looking for is the SQL ORDER BY FIELD function. In Ruby it should be something like this:
Case.where(user: #user).order("FIELD(name, #{some name param variable}) desc")
Try this:
Case.joins(steptations: :step)
.group("cases.id")
.select("cases.*,
COUNT(steps.name) filter (where steps.name = 'shipped') as shipped")
.order(:shipped)

issue in scrollY in data table

I am want to add data table scroll Y feature its working fine but there is a problem of screen resolution . the screen leave more space from the bellow and it leave space from Y axis like bellow images .
my code-
html.erb
<table class="table table-striped table-hover" id="pendingpodatesort" >
<thead>
<tr>
<th><%= check_box_tag "selectAll", "selectAll" %></th>
<th>Item</th>
<th>Make/Catno</th>
<th>UOM</th>
<th>Qty</th>
<th>Qt_P</th>
<th>Vendor</th>
<th>Phone</th>
<th>No.</th>
<th>Date.</th>
<th>Sort Date</th>
<th>Dlv.Dt</th>
<th>Sort Date</th>
<th>Status</th>
<th>Status Dt</th>
<th>Remarks</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% #poitems.each do |poitem| %>
<tr>
<% if current_personnel.designation == 4 || current_personnel.designation == 5 %>
<td></td>
<% else %>
<td><%= check_box_tag 'poitem[]' , poitem.id %></td>
<% end %>
<td><%= poitem.item.description %></td>
<% if poitem.make_id != nil %>
<td><%= (poitem.make.brand.name)+"/"+(poitem.make.catno) %></td>
<%else %>
<td></td>
<% end%>
<% if poitem.uom_type == nil %>
<td><%= poitem.item.uom.shortform %></td>
<% else %>
<td><%= Uom.find_by_id((Item.find_by_id(poitem.item_id)).dual_uom_id).shortform %></td>
<% end %>
<td><%= poitem.quantity %></td>
<% if poitem.pending_quantity != nil %>
<td><%= poitem.pending_quantity %></td>
<%else%>
<td><%= poitem.quantity %></td>
<%end%>
<td><%= poitem.purchaseorder.vendor.description.titlecase %></td>
<td><%= poitem.purchaseorder.vendor.ref_ph %></td>
<td>PO/<%= poitem.indent.parentindent.warehouse.shortform + "/"+(poitem.purchaseorder.serial.to_s) %></td>
<% #podate=poitem.purchaseorder.date %>
<td><%= #podate.strftime("%d/%m") %></td>
<td><%= #podate.strftime("%m/%d/%y") %></td>
<% #delivery_days=poitem.purchaseorder.delivery_days %>
<% if #delivery_days != nil %>
<td><%= (#podate+(#delivery_days.days)).strftime("%d/%m") %></td>
<td><%= (#podate+(#delivery_days.days)).strftime("%m/%d/%y") %></td>
<% else %>
<td></td>
<td></td>
<% end %>
<% if poitem.purchaseorder.awaiting_pi_payment==true %>
<td>Awaiting for PI Payment</td>
<td></td>
<% elsif poitem.dispatched==true %>
<td>Despatched</td>
<% if poitem.dispatched_date != nil %>
<td><%= poitem.dispatched_date.strftime("%d/%m") %></td>
<% else %>
<td></td>
<% end %>
<% elsif poitem.received_by_transporter==true %>
<td>Received at Transporter Godown</td>
<% if poitem.received_by_transporter_on != nil %>
<td><%= poitem.received_by_transporter_on.strftime("%d/%m") %></td>
<% else %>
<td></td>
<% end %>
<% elsif poitem.delivered_at_plant==true %>
<td>Delivered at Plant</td>
<% if poitem.delivered_at_plant_on != nil %>
<td><%= poitem.delivered_at_plant_on.strftime("%d/%m") %></td>
<% else %>
<td></td>
<% end %>
<% else %>
<td></td>
<td></td>
<% end %>
<% if poitem.dispatch_details==nil %>
<td><%= (poitem.followup_remarks) %></td>
<% elsif poitem.followup_remarks==nil %>
<td><%= (poitem.dispatch_details)%></td>
<% else %>
<td><%= (poitem.dispatch_details)+', '+ (poitem.followup_remarks) %></td>
<% end %>
<% if PoAttachment.where(po_id: poitem.po_id)[0]== nil %>
<td></td>
<% else %>
<td><% PoAttachment.where(po_id: poitem.po_id).each do |attachment| %>
<%= link_to attachment.document.url, class: "btn btn-default btn-xs" do %>
<i class="glyphicon glyphicon-paperclip"></i><% end %>
<% end %></td>
<% end %>
<td> <%= link_to controller: "purchase_order_items", action: "change_status", id: poitem.id, class: "btn btn-default btn-xs" do%>
<i class="glyphicon glyphicon-pencil"></i>
<% end %></td>
<td><%= submit_tag ">", name: poitem.id, :class => 'btn btn-default btn-xs' %></td>
</tr>
<% end %>
</tbody>
</table>
application.js
$(document).ready(function(){
var filterTable=$("#pendingpodatesort").DataTable({
"dom": '<"wrapper"ilt>',
"scrollY": '510px',
"scrollX": true,
"lengthMenu": [ [-1, 10, 25, 50, 100], ["All", 10, 25, 50, 100] ],
"aoColumns": [
{"bSortable": true},
{"bSortable": true},
{"bSortable": true},
{"bSortable": true},
{"bSortable": true},
{"bSortable": true},
{"bSortable": true},
{"bSortable": true},
{"bSortable": true},
{"iDataSort": 10},
{"bVisible": false},
{"iDataSort": 12},
{"bVisible": false},
{"bSortable": true},
{"bSortable": true},
{"bSortable": true},
{"bSortable": true},
{"bSortable": true},
{"bSortable": true}
],
"order": [[ 10, "desc" ]]
});
$("#filterbox").keyup(function() {
filterTable.search(this.value).draw();
});
});
How can i adjust this size with out increase zoom on any screen?is there any option to give scroll Y value in %?
Add
scrollCollapse: true
Reference: https://datatables.net/reference/option/scrollCollapse

Form_tag do not add check_box_tag value into parameters

I have Pieces model, which is store item's parts. When I need, I'm asking to users, check pieces is ok or nok with generated forms.
I am creating reports model to store the forms which I asked from users.
So, when I generate the forms check_box and and text_field works fine. But when I submit the form, I can't get check_box values as a parameter.
{"utf8"=>"✓",
"_method"=>"patch",
"authenticity_token"=>"5OmdXCDixwxru2yBtB3YmT3YF/ZqOByoAJ3J29TyJikxJdA+RXAvGjwu8MBIPlJCROFx4V7AUcA7IIqIgthD9g==",
"notes"=>{"79"=>"asdasda","84"=>""},
"commit"=>"Submit",
"id"=>"5"}
here is my edit.html.erb
<%- model_class = Report -%>
<div class="page-header">
<h1><%=t '.title', :default => [:'helpers.titles.edit', 'Edit %{model}'], :model => model_class.model_name.human.titleize %></h1>
</div>
<% if #report.errors.any? %>
<div id="error_expl" class="panel panel-danger">
<div class="panel-heading">
<h3 class="panel-title"><%= pluralize(#report.errors.count, "error") %> prohibited this report from being saved:</h3>
</div>
<div class="panel-body">
<ul>
<% #report.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
</div>
<% end %>
<table class="table table-striped">
<thead>
<tr>
<th><%= model_class.human_attribute_name(:status) %></th>
<th><%= model_class.human_attribute_name(:serial_no) %></th>
<th><%= model_class.human_attribute_name(:category) %></th>
<th><%= model_class.human_attribute_name(:name) %></th>
<th><%= model_class.human_attribute_name(:brand) %></th>
<th><%= model_class.human_attribute_name(:model) %></th>
<th><%= model_class.human_attribute_name(:quantity) %></th>
</tr>
</thead>
<tbody>
<%= form_tag(report_path(#report), :method => :patch) do %>
<% #pieces.each do |piece| %>
<tr>
<td><div class="form-group">
<%= check_box_tag(:status, name: "status["+piece.id.to_s+"]", class: 'form-control') %>
</div></td>
<td><%= piece.try(:serial_no) %></td>
<td><%= piece.item.category.name %></td>
<td><%= piece.item.name %></td>
<td><%= piece.item.brand %></td>
<td><%= piece.item.model %></td>
<% if piece.serial_no.start_with?("D") %>
<td><%= piece.item.pieces.count %> <%= piece.item.unit.name %></td>
<% else %>
<td><%= piece.item.pieces.sum(:quantity) %> <%= piece.item.unit.name %></td>
<% end %>
</tr>
<tr>
<td colspan=7 class="hidden" id="hebele">
<%= text_field_tag(:note,"", placeholder: "Note ", name: "notes["+piece.id.to_s+"]",class: "form-control ") %>
</td>
</tr>
<% end %>
</tbody>
</table>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<%= submit_tag("Submit",:class => 'btn btn-primary') %>
<%= link_to t('.cancel', :default => t("helpers.links.cancel")), reports_path, :class => 'btn btn-default' %>
</div>
</div>
<% end %>
<script type="text/javascript">
$("[id='status']").bootstrapSwitch({
size: 'mini',
onColor: 'success',
offColor: 'danger',
indeterminate: true,
onSwitchChange: function(event, state) {
if (state == false){
$("#hebele").removeClass('hidden');
}else if(state == true){
$("#hebele").addClass('hidden');
}
}
});
</script>
controller:
def edit
#pieces = #report.pieces.joins(:item).group(:item_id)
#report = Report.find(params[:id])
end
You need to define the value of the check_box_tag:
<%= check_box_tag :status, piece.id, class: 'form-control' %>
If you're editing a #report, you'll be best using form_for:
<table>
<tbody>
<%= form_for #report do |f| %>
<% #pieces.each do |piece| %>
<tr>
<td>
<div class="form-group">
<%= f.check_box :status, class: 'form-control', price.id %>
</div>
</td>
<td><%= piece.try(:serial_no) %></td>
<td><%= piece.item.category.name %></td>
<td><%= piece.item.name %></td>
<td><%= piece.item.brand %></td>
<td><%= piece.item.model %></td>
<% if piece.serial_no.start_with?("D") %>
<td><%= piece.item.pieces.count %> <%= piece.item.unit.name %></td>
<% else %>
<td><%= piece.item.pieces.sum(:quantity) %> <%= piece.item.unit.name %></td>
<% end %>
</tr>
<tr>
<td colspan=7 class="hidden" id="hebele">
<%= f.text_field :note, placeholder: "Note", class: "form-control" %>
</td>
</tr>
<% end %>
<tr><td colspan="7"><%= f.submit, class: "btn btn-primary" %></td></tr>
<% end %>
</tbody>
</table>

How to change values which get from check box into SQL condition?

I use check_box_tag to get selected beacon, and i to use collection_select to define a value. when user press the button, I want to all selected beacons change value into what collection_select choose, but I don't know how to use ids[] to set my condition like "where...in ..."
here is my action, I want params[:ids] change in to just like [1,2,3]
#beacons = Beacon.where(:id => params[:ids]).update_all(:installer_id => params[:account][:installer_id])
here is my table:
<table class="col-md-12 table-bordered table-striped table-condensed cf">
<thead class="cf">
<th>Check</th>
<th>BeaconUUID</th>
<th>BeaconCategory</th>
<th>BeaconLocate</th>
<th>BeaconName</th>
<th>BeaconAddress</th>
<th>Assign</th>
</thead>
<tbody>
<% #beacons.each do |beacon| %>
<tr>
<td><%= check_box_tag "ids[]", beacon.id %></td>
<td><%= beacon.beacon_uuid %></td>
<td><%= beacon.cid %></td>
<td><%= beacon.lid %></td>
<td><%= beacon.beacon_name %></td>
<td><%= beacon.beacon_address %></td>
<% if beacon.installer_id.nil? %>
<td>not assign</td>
<% else %>
<td>assigned:<%= beacon.installer_id %></td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
<%= form_tag assigned_beacons_path, :method => 'post' do %>
<td><%= collection_select(:account, :installer_id, Account.where('manager_id = ?',session[:user_id]), :id, :email, {:prompt => 'choose!'}, :style => "width: 100px;") %></td>
<td><p data-placement="top" data-toggle="tooltip" title="Edit"><%= submit_tag 'assign', class: "btn btn-info btn-xs"%></p></td>
<% end %>
As was pointed out in comments, check_box_tag should be moved inside of form_tag block:
<%= form_tag assigned_beacons_path, :method => 'post' do %>
<table class="col-md-12 table-bordered table-striped table-condensed cf">
<thead class="cf">
<th>Check</th>
<th>BeaconUUID</th>
<th>BeaconCategory</th>
<th>BeaconLocate</th>
<th>BeaconName</th>
<th>BeaconAddress</th>
<th>Assign</th>
</thead>
<tbody>
<% #beacons.each do |beacon| %>
<tr>
<td><%= check_box_tag "ids[]", beacon.id %></td>
<td><%= beacon.beacon_uuid %></td>
<td><%= beacon.cid %></td>
<td><%= beacon.lid %></td>
<td><%= beacon.beacon_name %></td>
<td><%= beacon.beacon_address %></td>
<% if beacon.installer_id.nil? %>
<td>not assign</td>
<% else %>
<td>assigned:<%= beacon.installer_id %></td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
<td><%= collection_select(:account, :installer_id, Account.where('manager_id = ?',session[:user_id]), :id, :email, {:prompt => 'choose!'}, :style => "width: 100px;") %></td>
<td><p data-placement="top" data-toggle="tooltip" title="Edit"><%= submit_tag 'assign', class: "btn btn-info btn-xs"%></p></td>
<% end %>
Also, dangling <td> blocks don't look good, you should move them into this or another <table> as well.

will_paginate in the same page for the same instance variable but for three different displays

This is the controller I have writter for Orders.
def index
if current_user.has_role? :admin
#orders = Order.all.paginate(:page => params[:page], :per_page => 5)
elsif current_user.has_role? :customer
#orders = Order.where(:email => current_user.email).paginate(:page => params[:page], :per_page => 5)
elsif current_user.has_role? :white_label
#orders = Order.where(:performer_id => (Performer.where(:white_label_id => current_user.white_label.id))).paginate(:page => params[:page], :per_page => 5)
else
#orders = current_user.performer.orders.paginate(:page => params[:page], :per_page => 5)
end
#custom_video = CustomVideo.new
end
As you see I have used will_paginate gem to do pagination. This is the view page where I am doing pagination.
<div class="container">
<div class="span 8">
<% if current_user.has_role? :admin %>
<%role =1%>
<%elsif current_user.has_role? :performer %>
<%role =2%>
<% else %>
<%role =3%>
<% end %>
<h3>Awaiting Upload</h3>
<table id="order_table" class="table table-hover">
<thead>
<tr>
<th>id</th>
<th>Location</th>
<th>Performer</th>
<th>Duration</th>
<th>Quality</th>
<th>Delivery</th>
<th>Category</th>
<th>Description</th>
<th>Total</th>
<% if role==2 %>
<th>Select a video to upload for the order</th>
<%end %>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% #orders.each do |order| %>
<% if order.delivery_time_id=1%>
<% var1=14 %>
<% else %>
<% var1=7 %>
<% end %>
<% if !CustomVideo.find_by_order_id(order.id) and Time.now <= order.created_at.to_date + var1.days%>
<tr>
<td> <%= order.id%></td>
<td><% if order.location %>
<%= order.location.name %>
<% end %></td>
<td><% if order.performer %>
<%= order.performer.first_name %>
<% end %></td>
<td><% if order.duration %>
<%= order.duration.time %>
<% end %></td>
<td><% if order.quality %>
<%= order.quality.name %>
<% end %></td>
<td><% if order.delivery_time %>
<%= order.delivery_time.duration %>
<% end %></td>
<td><% if order.clip_category %>
<%= order.clip_category.name %>
<% end %></td>
<td><% if order.description %>
<%= order.description %>
<% end %></td>
<td><%= order.total %></td>
<% if role==2 %>
<td>
<%= simple_form_for(#custom_video, :html => { :multipart => true, :id => "fileupload" }) do |f| %>
<%= f.error_notification %>
<%= f.file_field :path%><br/><br>
<%= f.hidden_field :order_id,:value => order.id %>
<%=f.button :submit, :value=>"Save", :class=>"btn btn-success" %>
<% end %>
<script id="template-upload" type="text/x-tmpl">
<div class="upload">
{%=o.name%}
<div class="progress"><div class="bar" style="width: 0%"></div></div>
</div>
</script>
<%end%>
</td>
<td>
<% if role==1 %>
<%=form_tag({controller: "orders", action: "refund"}, method: "post") do%>
<%= hidden_field_tag(:id, order.id) %>
<%= submit_tag ("Refund"),:class => "btn btn-success download" %>
<% end %>
<% end %>
</td>
<% if can? :show, #order %>
<td><%= link_to 'Show', order %></td>
<% end %>
<% if can? :update, #order %>
<td><%= link_to 'Edit', edit_order_path(order) %></td>
<% end %>
<% if can? :destroy, #order %>
<td><%= link_to 'Destroy', order, method: :delete, data: { confirm: 'Are you sure?' } %>
</td>
<%else %>
<% next %>
<%end %>
<% end -%>
<% end %>
<%= will_paginate #orders, :param_name => 'awaiting_orders' %>
</tbody>
</table><br/>
<h3>Completed Orders</h3>
<table class="table table-hover" id="order_table">
<thead>
<tr>
<th>id</th>
<th>Location</th>
<th>Performer</th>
<th>Duration</th>
<th>Quality</th>
<th>Delivery</th>
<th>Category</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% #orders.each do |order| %>
<% if order.delivery_time_id=1%>
<% var1=14 %>
<% else %>
<% var1=7 %>
<% end %>
<% if CustomVideo.find_by_order_id(order.id) and Time.now <= order.created_at.to_date+var1.days%>
<tr>
<td> <%= order.id%></td>
<td><%= order.location.name %></td>
<td><%= order.performer.first_name %></td>
<td><%= order.duration.time %></td>
<td><%= order.quality.name %></td>
<td><%= order.delivery_time.duration %></td>
<td><%= order.clip_category.name %></td>
<td>
<% if role==1 %>
<%=form_tag({controller: "orders", action: "refund"}, method: "post") do%>
<%= hidden_field_tag(:id, order.id) %>
<%= submit_tag ("Refund"),:class => "btn btn-success download" %>
<% end %>
<% end %>
</td>
<% if can? :show, #order %>
<td><%= link_to 'Show', order %></td>
<% end %>
<% if can? :update, #order %>
<td><%= link_to 'Edit', edit_order_path(order) %></td>
<% end %>
<% if can? :destroy, #order %>
<td><%= link_to 'Destroy', order, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<%else %>
<% next %>
<%end %>
<% end -%>
</tr>
<% end %>
<%= will_paginate #orders %>
</tbody>
</table><br/>
<h3>Expired Orders</h3>
<table class="table table-hover" id="order_table">
<thead>
<tr>
<th> id</th>
<th>Location</th>
<th>Performer</th>
<th>Duration</th>
<th>Quality</th>
<th>Delivery</th>
<th>Category</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% #orders.each do |order| %>
<% if order.delivery_time_id=1%>
<% var1=14 %>
<% else %>
<% var1=7 %>
<% end %>
<% if Time.now > order.created_at.to_date+var1.days%>
<tr>
<td> <%= order.id%></td>
<td><%= order.location.name %></td>
<td><%= order.performer.first_name %></td>
<td><%= order.duration.time %></td>
<td><%= order.quality.name %></td>
<td><%= order.delivery_time.duration %></td>
<td><%= order.clip_category.name %></td>
<% if can? :show, #order %>
<td><%= link_to 'Show', order %></td>
<% end %>
<% if can? :update, #order %>
<td><%= link_to 'Edit', edit_order_path(order) %></td>
<% end %>
<% if can? :destroy, #order %>
<td><%= link_to 'Destroy', order, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<%else %>
<% next %>
<%end %>
<% end -%>
</tr>
<% end %>
<%= will_paginate #orders %>
</tbody>
</table>
<br>
<h3>Orders Refunded</h3>
<table class="table table-hover" id="order_table">
<thead>
<tr>
<th> id</th>
<th>Location</th>
<th>Performer</th>
<th>Duration</th>
<th>Quality</th>
<th>Delivery</th>
<th>Category</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% #orders.each do |order| %>
<% if order.refunded %>
<tr>
<td> <%= order.id%></td>
<td><%= order.location.name %></td>
<td><%= order.performer.first_name %></td>
<td><%= order.duration.time %></td>
<td><%= order.quality.name %></td>
<td><%= order.delivery_time.duration %></td>
<td><%= order.clip_category.name %></td>
<% if can? :show, #order %>
<td><%= link_to 'Show', order %></td>
<% end %>
<% if can? :destroy, #order %>
<td><%= link_to 'Destroy', order, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<%else %>
<% next %>
<%end %>
<% end -%>
</tr>
<% end %>
<%= will_paginate #orders %>
</tbody>
</table>
<br>
</div>
</div>
<%# link_to 'New Order', new_order_path %>
The problem in this is that. If I click the second page for the first table, it is going to the second for the next table too. I have tried giving the :param_name => 'questions_page' suggested here. But the trouble here is that, I am not using different instance variable for the tables but the same one. How do I solve this?>
You've almost answered your own question. You need to be using separate instance variables for each table if you want them to behave separately.

Resources