3. RubyGems vs Gem
● Gem is a libraries (a collection of code to do
something)
e.g. rails, rspec, rake, bundler, will_paginate, kaminari,...
● RubyGems is a tool designed to easily manage
the installation of gems, and a server for
distributing them.
e.g. gem list, gem install, gem uninstall,
gem –help command (#list all gem commands)
4. RVM, Bundler
● RVM (Ruby Version Manager) is a command-
line tool which allows you to easily install,
manage, and work with multiple ruby
environments from interpreters to sets of gems.
e.g. rvm list, rvm install, rvm use, rvm gemset create,...
● Bundler is a gem to manage your application's
gem dependencies with less pain. (after install
ruby)
e.g. bundle install, bundle update,...
5. Gemset, rvmrc
● Gemset is a set of gems.
e.g. rvm gemset list, rvm gemset create rails4
● rvmrc is a dot file in repo to auto choose
gemset ...
e.g. rvm gemset create rails4, rvm gemset use rails4, rvm
gemset use rails4, rvm gemset create rails4
6. will_paginate
● Introduction:
will_paginate is a pagination library that integrates with Ruby on Rails, Sinatra, Merb,
DataMapper and Sequel.
● Set up Git:
$ git init
$ git add --all
$ git commit -m 'before will_paginate'
● How to Use:
1) Add in Gemfile & bundle install
gem 'will_paginate', '~> 3.0'
2) perform a paginated query
Movie.released.paginate(page: params[:page], per_page: 3)
7. will_paginate
3) render page links in the view
4) see the result in browser
5) make those pagination links prettier
# Download css or sass from “http://mislav.uniqpath.com/will_paginate/”
into “app/assets/stylesheets/”
# add in applications.css
*= require pagination
6) Use css class in the paginate helper
<%= will_paginate @movies, class: 'flickr_pagination' %>
<%= will_paginate @movies %>
8. will_paginate
7) See the result
● Git Commit:
$ git status
$ git add --all
$ git commit -m 'added will_paginate'
9. kaminari
●
Introduction:
A Scope & Engine based, clean, powerful, customizable
and sophisticated paginator for modern web app
frameworks and ORMs.
● How to Use:
1)Add in Gemfile & bundle install
gem 'kaminari'
2) perform a paginated query
Movie.released.page(params[:page]).per(3)
10. kaminari
3) render page links in the view
<%= paginate @movies %>
4) see the result in browser
5) play around with theme
$ rails g kaminari:views # to list themes
$ rails g kaminari:views google
$ rails d kaminari:views google # destroy theme
$ rails g kaminari:views bootstrap
11. kaminari
6) play around with helper & locales
- delete first, last and keep previous & next
- use outer_windows: 3
- use link_to_next_page, link_to_previous_page
Git commit
$ git status
$ git add --all
$ git commit -m 'kaminari with some custome'
13. Practice
● Add header paginate have Previous and Next buttons
● Add footer paginate with outer_window: 3 in bootstrap
theme and no first and last link