Rails 搜索将分页

Rails search with will Paginate

在我使用的代码下方 now.Current 代码分页将显示每个 page.Currently 搜索功能 100 个用户 使用 JQuery code.Since 分页显示 100 条记录,搜索仅工作100 条记录。我需要用 will paginate.If 实现搜索我搜索用户,它将从数据库中获取详细信息并显示在 table 中。任何人都可以建议如何用 will 在 rails 中分页实现吗?

控制器

 @user_list = User.all.paginate(:page => params[:page], :per_page => 100)

html.erb

 <%= will_paginate @user_list %>
<table id="users_access_table">
  <thead>
    <tr>
    <th>Name</th>
    <th>Email</th>
    <th>Curernt Access</th>
    <th>API User Access</th>
     </tr>
  </thead>
  <tbody id="table_body">
  <br>
  <div class="col-md-4" style="float: left;">
    <input class="form-control" title="Search" type="text" id="userinput" onkeyup=" searchUsers()" placeholder="Search &#x1F50D; :">
  </div>
  <br>
  <br>
  <% @user_list.each do |user| %>
    <tr>
      <td>
        <%=user['name']%>
      </td>
      <td>
        <%=user['email']%>
      </td>
       <td>
        <%=user['access']%>
      </td>
       <td>
        <%=user['api_users']%>
      </td>
      
 </td>
        
       <td>
 

您还需要在控制器级别和 UI 方面进行更改。

我正在考虑参数从 UI 端传到控制器,并在用户控制器上更改查询。

您需要创建 LIKE 查询而不是 all

@user_list = User.all.paginate(:page => params[:page], :per_page => 100)

改成

@user_list = User.where("name LIKE ? OR email LIKE ?", "%#{search_param}%", "%#{search_param}%").page(params[:page]).per(100)

希望它能帮助您解决问题。