don*_*iao 9 ruby ruby-on-rails kaminari
我用kaminari,并且错误.
的Gemfile:
# gem 'will_paginate', '~> 3.0.6'
# gem 'will_paginate-bootstrap'
gem 'kaminari'
Run Code Online (Sandbox Code Playgroud)
lists_controller.rb
def index
if params[:tag]
@lists = List.tagged_with(params[:tag]).order(created_at: :desc).paginate(page:params[:page], per_page: 3 )
else
@lists = List.all.order(created_at: :desc)
end
end
Run Code Online (Sandbox Code Playgroud)
我也是用户.page params[:page].per(2)关注.order(created_at: :desc)
但不工作
视图/列表/ index.html.erb
<%= paginate @lists %>
Run Code Online (Sandbox Code Playgroud)
错误在这里
undefined method `total_pages' for #<List::ActiveRecord_Relation:0x007fa2303e3fa8>
Extracted source (around line #26):
</div>
</div>
<%= paginate @lists %>
<div class="container">
<div class="row">
<div class="col-md-8">
Run Code Online (Sandbox Code Playgroud)
我不知道怎么做,我复制关于kaminari的railscast,视频很好,我有一个bug.谢谢,帮助我.
您需要对两个查询进行分页.我建议像:
def index
if params[:tag]
@lists = List.tagged_with(params[:tag])
else
@lists = List.all
end
@lists = @lists.order(created_at: :desc).paginate(page:params[:page], per_page: 3 )
end
Run Code Online (Sandbox Code Playgroud)
否则,@lists当params[:tag]nil 时不会是分页对象.
| 归档时间: |
|
| 查看次数: |
10267 次 |
| 最近记录: |