Ruby on rails kaminari带ror至分页
我第一次尝试使用kaminari分页,但出现错误:Ruby on rails kaminari带ror至分页,ruby-on-rails,kaminari,Ruby On Rails,Kaminari,我第一次尝试使用kaminari分页,但出现错误: views/store/index.html.erb where line #23 raised: undefined method `current_page' for #<Array:0x3ebe0c0> Extracted source (around line #23): 20: </div> 21: </div> 22: <%end%> 23: <%= paginat
views/store/index.html.erb where line #23 raised:
undefined method `current_page' for #<Array:0x3ebe0c0>
Extracted source (around line #23):
20: </div>
21: </div>
22: <%end%>
23: <%= paginate @buildings %>
存储>索引
<%= paginate @buildings %>
<%= will_paginate @buildings %>
我做错了什么???删除中的
all
@buildings = Building.all.page(params[:page]).per(1)
像这样
@buildings = Building.page(params[:page]).per(1)
你可以走了。ActiveRecord
all
方法返回一个数组,我相信Kaminari不希望数组工作。我已经更改了Kaminari,我已经使用了will\u paginate,并且工作得很疯狂
归档
gem'will_paginate','>=3.0.pre'
仪表板内=>bundle安装
店内>索引
<%= paginate @buildings %>
<%= will_paginate @buildings %>
在控制器>存储控制器中
def index
@buildings = Building.all.page(params[:page]).per(1)
respond_to do |format|
format.html # index.html.erb
format.json { render json: @buildings }
end
end
@buildings=Building.paginate:page=>params[:page],:order=>'created_at DESC',:per_page=>1
完成了!您可以使用paginatethx获得帮助,但实际上不起作用。在那之后,给了我越来越多的错误,比如。我已经改变了洞的东西,现在正在工作