Hey, Well Friends, if you are searching Pagination code for your rails application, then I think This
gem will help you. This is Kaminari gem, It is a clean, easy and flexible solution which uses scopes to flow nicely with Models.
for using this gem, Suppose you create a model name 'Posts', and you want to adjust your posts through pagination. so now
1. First thing First, Add this gem in your gemfile, like this :
2. Now, if "The Gemfile's dependencies are satisfied" then run the command
en:
hello: "Hello world"
views:
pagination:
previous: "< Previous"
next: "Next >"
truncate: "..."
5. Now finally on your views section add
gem will help you. This is Kaminari gem, It is a clean, easy and flexible solution which uses scopes to flow nicely with Models.
for using this gem, Suppose you create a model name 'Posts', and you want to adjust your posts through pagination. so now
1. First thing First, Add this gem in your gemfile, like this :
$ gem 'kaminari'
and run the bundle command in your terminal.2. Now, if "The Gemfile's dependencies are satisfied" then run the command
$ rails g kaminari:views default
3. Now go on your posts controller and add this code:$
@posts = Post.order("name").page(params[:page]).per(5)
4. Now go to your config/locales/en.yml file and paste this code, and then adjust it according to you.en:
hello: "Hello world"
views:
pagination:
previous: "< Previous"
next: "Next >"
truncate: "..."
5. Now finally on your views section add
$
<%= paginate @posts %>
That's it now I hope Pagination doing perfect, if you face any problem just comment it.
Comments
Post a Comment