刘华佼的全栈学习记录

如何加入分页功能

| Comments

目标

加入分页功能

步骤一:

安装will_paginate
gem 'will_paginate’

步骤二:

bundle install

步骤三:

重开server

步骤四:

修改 app/controllers/groups_controller.rb 中的 show
@posts = @group.posts.recent.paginate(:page => params[:page], :per_page => 5)

步骤五:

修改 groups/show.html.erb

<div class="text-center">
  <%= will_paginate @posts %>
</div>

Comments

comments powered by Disqus