ruby - Display notification if search is not found using Rails 3 -
i using will_paginate gem
searching data table per 2 date.here requirement if no search data found there should 1 notification user i.e-"no record found in between these 2 date."
.mu code files given below.
view_report.html.erb:
<div class="col-md-4 col-md-offset-1"> <div class="text-left"> </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 |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 ?', "%#{search}%") where("created_on >= ? , created_on <= ?", search, search1 ) else scoped end end end
please me add notification per requirement.
try this:
<% if @sdf.blank? %> <p>no record found in between these 2 date.</p> <% else %> <table class="table table-bordered"> .... <thead> .... </thead> <tbody> <% @sdf.each |sdf| %> .... <% end %> </tbody> </table> <%= will_paginate @sdf %> <% end %>
Comments
Post a Comment