我正在尝试使用will_paginate进行搜索,使用Ransack进行分页,我收到以下错误:#
的未定义方法`total_pages'我不确定我在这里做错了什么,并尝试了许多可能的解决方案而没有运气。是否可以将这些一起使用,我在这里做错了什么?谢谢。
coin_controller.rb
class CoinsController < ApplicationController
load_and_authorize_resource param_method: :question_params
before_action :find_coin, only: [:edit, :update, :destroy ]
before_action :authenticate_user!, except: [:index, :create, :show]
def index
@search = Coin.ransack(params[:q])
@coins = @search.result.paginate(page: params[:page], per_page: params[:per_page])
end
.
.
.
end
index.html.erb
<% provide(:title, "Coins") %>
<% @coins = @coins.sort_by &:currency_name %>
<%= will_paginate @coins %>
<div class="row">
<div class="col-md-8" id="pagination_table">
<% @coins.each do |coin| %>
<% if coin.accepted %>
<ul>
<%= image_tag coin.picture.thumb.url if coin.picture? %>
<%= link_to coin.currency_name, :action => 'show', :id => coin %>
</ul>
<% end %>
<% end %>
<% if can? :edit, Coin %>
<hr><b>Pending Approval</b><hr>
<% @coins.each do |coin| %>
<% if not coin.accepted %>
<ul>
<%= image_tag coin.picture.thumb.url if coin.picture? %>
<%= link_to coin.currency_name, :action => 'show', :id => coin %>
</ul>
<% end %>
<% end %>
<% end %>
</div>
<div class="col-md-3" id="side-bar">
<%= link_to "Submit a New Coin", new_coin_path, class: "btn btn-default" %>
<fieldset class="search-field">
<legend>Search All Coins</legend>
<%= search_form_for @search do |f| %>
<div class="field">
<%= f.label :currency_name_cont, "Search by Name" %>
<%= f.text_field :currency_name_cont %>
</div>
<div class="actions"><%= f.submit "Search" %></div>
<div class="field">
<%= f.label "Search by Genre" %><br />
<%= f.collection_check_boxes :genres_id_in_any, Genre.all, :id, :displayname do |b| %>
<div class="collection-check-box">
<%= b.check_box %>
<%= b.label %>
</div>
<% end %>
</div>
<div class="actions"><%= f.submit "Search" %></div>
<% end %>
</fieldset>
</div>
</div>
<script>
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
</script>
我也试过使用Kaminari并得到了同样的错误。
答案 0 :(得分:0)
试试这个解决方案......
而不是这一行
<%= will_paginate @coins %>
要
<%= will_paginate @coins if @coins.present? %>