Commit 904865d8 by Thanh Hung Pham

Change pagin with kaminari gem

parent 0981b651
...@@ -52,11 +52,10 @@ group :development do ...@@ -52,11 +52,10 @@ group :development do
gem 'binding_of_caller' gem 'binding_of_caller'
gem 'devise' gem 'devise'
gem 'figaro' gem 'figaro'
gem 'kaminari'
gem 'rubyzip' gem 'rubyzip'
gem 'spring' gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0' gem 'spring-watcher-listen', '~> 2.0.0'
gem 'will_paginate', '3.1.5'
gem 'bootstrap-will_paginate', '1.0.0'
end end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
......
...@@ -49,8 +49,6 @@ GEM ...@@ -49,8 +49,6 @@ GEM
bindex (0.5.0) bindex (0.5.0)
binding_of_caller (0.7.2) binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1) debug_inspector (>= 0.0.1)
bootstrap-will_paginate (1.0.0)
will_paginate
builder (3.2.3) builder (3.2.3)
byebug (9.0.6) byebug (9.0.6)
capybara (2.14.4) capybara (2.14.4)
...@@ -95,6 +93,18 @@ GEM ...@@ -95,6 +93,18 @@ GEM
rails-dom-testing (>= 1, < 3) rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0) railties (>= 4.2.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
kaminari (1.0.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.0.1)
kaminari-activerecord (= 1.0.1)
kaminari-core (= 1.0.1)
kaminari-actionview (1.0.1)
actionview
kaminari-core (= 1.0.1)
kaminari-activerecord (1.0.1)
activerecord
kaminari-core (= 1.0.1)
kaminari-core (1.0.1)
listen (3.1.5) listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4) rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7) rb-inotify (~> 0.9, >= 0.9.7)
...@@ -196,7 +206,6 @@ GEM ...@@ -196,7 +206,6 @@ GEM
websocket-extensions (0.1.2) websocket-extensions (0.1.2)
whenever (0.9.7) whenever (0.9.7)
chronic (>= 0.6.3) chronic (>= 0.6.3)
will_paginate (3.1.5)
xpath (2.1.0) xpath (2.1.0)
nokogiri (~> 1.3) nokogiri (~> 1.3)
...@@ -207,7 +216,6 @@ DEPENDENCIES ...@@ -207,7 +216,6 @@ DEPENDENCIES
bcrypt (~> 3.1.7) bcrypt (~> 3.1.7)
better_errors better_errors
binding_of_caller binding_of_caller
bootstrap-will_paginate (= 1.0.0)
byebug byebug
capybara (~> 2.13) capybara (~> 2.13)
coffee-rails (~> 4.2) coffee-rails (~> 4.2)
...@@ -215,6 +223,7 @@ DEPENDENCIES ...@@ -215,6 +223,7 @@ DEPENDENCIES
figaro figaro
jbuilder (~> 2.5) jbuilder (~> 2.5)
jquery-rails jquery-rails
kaminari
listen (>= 3.0.5, < 3.2) listen (>= 3.0.5, < 3.2)
mysql2 (>= 0.3.18, < 0.5) mysql2 (>= 0.3.18, < 0.5)
puma (~> 3.7) puma (~> 3.7)
...@@ -229,7 +238,6 @@ DEPENDENCIES ...@@ -229,7 +238,6 @@ DEPENDENCIES
uglifier (>= 1.3.0) uglifier (>= 1.3.0)
web-console (>= 3.3.0) web-console (>= 3.3.0)
whenever whenever
will_paginate (= 3.1.5)
BUNDLED WITH BUNDLED WITH
1.15.1 1.15.1
...@@ -31,20 +31,20 @@ class JobsController < ApplicationController ...@@ -31,20 +31,20 @@ class JobsController < ApplicationController
def show def show
unless params[:city_id].nil? unless params[:city_id].nil?
@job_count = Job.where(city_id: params[:city_id]).count @job_count = Job.where(city_id: params[:city_id]).count
@jobs = Job.where(city_id: params[:city_id]).paginate(page: params[:page]) @jobs = Job.where(city_id: params[:city_id]).page params[:page]
@search_conditions = "All jobs in #{City.find(params[:city_id]).name}" @search_conditions = "All jobs in #{City.find(params[:city_id]).name}"
end end
unless params[:category_id].nil? unless params[:category_id].nil?
@job_ids = JobCategory.where(category_id: params[:category_id]).select(:job_id) @job_ids = JobCategory.where(category_id: params[:category_id]).select(:job_id)
@job_count = Job.where(id: @job_ids).count @job_count = Job.where(id: @job_ids).count
@jobs = Job.where(id: @job_ids).paginate(page: params[:page]) @jobs = Job.where(id: @job_ids).page params[:page]
@search_conditions = "All jobs in #{Category.find(params[:category_id]).name}" @search_conditions = "All jobs in #{Category.find(params[:category_id]).name}"
end end
unless params[:company_id].nil? unless params[:company_id].nil?
@job_count = Job.where(company_id: params[:company_id]).count @job_count = Job.where(company_id: params[:company_id]).count
@jobs = Job.where(company_id: params[:company_id]).paginate(page: params[:page]) @jobs = Job.where(company_id: params[:company_id]).page params[:page]
@search_conditions = "All jobs in #{Company.find(params[:company_id]).name}" @search_conditions = "All jobs in #{Company.find(params[:company_id]).name}"
end end
end end
......
...@@ -6,5 +6,7 @@ class Job < ApplicationRecord ...@@ -6,5 +6,7 @@ class Job < ApplicationRecord
has_many :job_category has_many :job_category
paginates_per 20
validates :name, presence: true, length: { maximum: 200 } validates :name, presence: true, length: { maximum: 200 }
end end
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
</h3> </h3>
</div> </div>
</div> </div>
<%= will_paginate %> <%= paginate @jobs %>
<div class="table-responsive"> <div class="table-responsive">
<table class="table"> <table class="table">
<thead> <thead>
...@@ -51,5 +51,5 @@ ...@@ -51,5 +51,5 @@
</table> </table>
</div> </div>
<%= will_paginate %> <%= paginate @jobs %>
</div> </div>
# frozen_string_literal: true
Kaminari.configure do |config|
config.default_per_page = 25
config.max_per_page = 20
# config.window = 4
# config.outer_window = 0
# config.left = 0
# config.right = 0
config.page_method_name = :page
config.param_name = :page
config.params_on_first_page = false
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment