create paginate by kaminari

parent dc54f45e
......@@ -33,7 +33,7 @@ gem 'whenever', require: false
gem 'rubocop', '~> 0.88.0', require: false
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
gem 'will_paginate', '3.3.0'
gem 'kaminari'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
......
......@@ -91,6 +91,18 @@ GEM
io-like (0.3.1)
jbuilder (2.10.0)
activesupport (>= 5.0.0)
kaminari (1.2.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.1)
kaminari-activerecord (= 1.2.1)
kaminari-core (= 1.2.1)
kaminari-actionview (1.2.1)
actionview
kaminari-core (= 1.2.1)
kaminari-activerecord (1.2.1)
activerecord
kaminari-core (= 1.2.1)
kaminari-core (1.2.1)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
......@@ -234,7 +246,6 @@ GEM
websocket-extensions (0.1.5)
whenever (1.0.0)
chronic (>= 0.6.3)
will_paginate (3.3.0)
xpath (3.2.0)
nokogiri (~> 1.8)
......@@ -248,6 +259,7 @@ DEPENDENCIES
chromedriver-helper
coffee-rails (~> 4.2)
jbuilder (~> 2.5)
kaminari
listen (>= 3.0.5, < 3.2)
mechanize (~> 2.7.6)
mysql2 (~> 0.5.3)
......@@ -264,7 +276,6 @@ DEPENDENCIES
uglifier (>= 1.3.0)
web-console (>= 3.3.0)
whenever
will_paginate (= 3.3.0)
RUBY VERSION
ruby 2.6.6p146
......
......@@ -7,3 +7,4 @@
padding: 5px;
}
class CitiesController < ApplicationController
def index
@cities_vietnam = City.all_city.vietnam
@cities_international = City.all_city.international
@cities_vietnam = City.vietnam
@cities_international = City.international
end
end
class JobsController < ApplicationController
def index
@cities = City.all
@industries = Industry.all
@total_job = Job.count
@jobs_list = Job.all_job
@jobs_list = Job.all_job.page(params[:page]).per(20)
end
end
......@@ -3,7 +3,6 @@ class City < ApplicationRecord
has_many :jobs, through: :city_jobs
scope :top_city, -> { joins(:jobs).group(:city_id).order('count(job_id) DESC').limit(9) }
scope :all_city, -> { joins(:jobs).group(:city_id).order('count(job_id) DESC') }
scope :vietnam, -> { where('location = 1') }
scope :international, -> { where('location = 0') }
scope :vietnam, -> { joins(:jobs).group(:city_id).order('count(job_id) DESC').where('location = 1') }
scope :international, -> { joins(:jobs).group(:city_id).order('count(job_id) DESC').where('location = 0') }
end
class IndustryJob < ApplicationRecord
belongs_to :industry
belongs_to :job
end
......@@ -16,7 +16,7 @@ class Job < ApplicationRecord
has_many :users, through: :histories
scope :limit_job, -> { limit(5).order(created_at: :desc) }
scope :all_job, -> { limit(20).order(created_at: :desc) }
scope :all_job, -> { all.order(created_at: :desc) }
def company_name
company&.name
......
<% provide(:title, 'Jobs') %>
<div class="container">
<div class="search-bar">
<%= render 'layouts/search_bar' %>
</div>
<div class="row total-jobs">
<div class="col-4">Total: <%= @total_job %> jobs</div>
<div class="col-4">Result for: ... jobs</div>
</div>
<div class="paginate-jobs">
<%= paginate @jobs_list, left: 3, right: 3 %>
</div>
<div class="job-list">
<%= render partial: "all_jobs", collection: @jobs_list, as: :job %>
</div>
<div class="paginate-jobs">
<%= paginate @jobs_list, left: 3, right: 3 %>
</div>
</div>
<li class="page-item">
<%= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, remote: remote, class: 'page-link' %>
</li>
<li class='page-item disabled'>
<%= link_to raw(t 'views.pagination.truncate'), '#', class: 'page-link' %>
</li>
<li class="page-item">
<%= link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, remote: remote, class: 'page-link' %>
</li>
<li class="page-item">
<%= link_to_unless current_page.last?, raw(t 'views.pagination.next'), url, rel: 'next', remote: remote, class: 'page-link' %>
</li>
<% if page.current? %>
<li class="page-item active">
<%= content_tag :a, page, data: { remote: remote }, rel: page.rel, class: 'page-link' %>
</li>
<% else %>
<li class="page-item">
<%= link_to page, url, remote: remote, rel: page.rel, class: 'page-link' %>
</li>
<% end %>
<%= paginator.render do %>
<nav>
<ul class="pagination">
<%= first_page_tag unless current_page.first? %>
<%= prev_page_tag unless current_page.first? %>
<% each_page do |page| %>
<% if page.left_outer? || page.right_outer? || page.inside_window? %>
<%= page_tag page %>
<% elsif !page.was_truncated? -%>
<%= gap_tag %>
<% end %>
<% end %>
<%= next_page_tag unless current_page.last? %>
<%= last_page_tag unless current_page.last? %>
</ul>
</nav>
<% end %>
<li class="page-item">
<%= link_to_unless current_page.first?, raw(t 'views.pagination.previous'), url, rel: 'prev', remote: remote, class: 'page-link' %>
</li>
......@@ -4,7 +4,6 @@
<div class="total-job">Having <%= @total_jobs %> jobs for you!</div>
</div>
</div>
<div class="container">
<div class="search-bar">
<%= render 'layouts/search_bar' %>
......
......@@ -53,26 +53,22 @@ class CSVImporter
description_job = "#{row["description"]} #{row["requirement"]}"
level = row["level"]
salary = row["salary"]
job = Job.find_or_create_by!(title: title_job,
description: description_job,
level: level,
salary: salary,
company_id: company.id)
next if job.blank?
industry_name = row["category"]
industries_relationship = Industry.find_by(name: industry_name)
next if industries_relationship.blank?
industry_relationship = find_or_create_by!(job_id: job.id,
industry_id: industries_relationship.id)
industries_relationship = Industry.where(name: industry_name)
location_data = row["work place"]
location = location_data.gsub('["', '').gsub('"]', '')
location_relationship = City.find_by(name: location)
next if location_relationship.blank?
city_relationship = find_or_create_by!(job_id: job.id,
industry_id: location_relationship.id)
location_relationship = City.where(name: location)
Job.find_or_create_by!(title: title_job,
description: description_job,
level: level,
salary: salary,
company_id: company_id) do |job|
job.industries << industries_relationship
job.cities << location_relationship
end
rescue StandardError => e
@logger.error e.message
......
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