Create Slug in City and Industry

parent 745be587
......@@ -25,3 +25,4 @@
.viet-nam, .international {
cursor: pointer;
}
......@@ -110,3 +110,16 @@
}
}
}
.result-for {
background-color: #99ff99;
border: 2px solid green;
border-radius: 12px;
text-align: center;
}
.total {
background-color: #b3ecff;
border: 2px solid #006080;
border-radius: 12px;
text-align: center;
font-size: 32px;
}
module Convert
def self.to_convert(str)
str.mb_chars.normalize(:kd).gsub(/[Đđ]/, 'd').gsub(/[^\x00-\x7F]/,'').gsub(/[\W+]/,' ').downcase.to_s.split(' ').join('-')
end
def self.to_convert_name(name)
name.mb_chars.normalize(:kd).gsub(/[Đđ]/, 'd').gsub(/[^\x00-\x7F]/,'').gsub(/[\W+0-9]/,' ').downcase.to_s.split(' ').join('-')
end
end
class JobsController < ApplicationController
before_action :use_variables
def index
@cities = City.all
@industries = Industry.all
@total_job = Job.count
@jobs_list = Job.all_job.page(params[:page]).per(20)
end
def city_jobs
@cities = City.all
@industries = Industry.all
@city = City.find_by(name: params[:name])
@city = City.find_by(converted_name: params[:converted_name])
@jobs_list = @city.jobs.all_job.page(params[:page]).per(20)
@total_job = Job.count
@result_for_job = @city.jobs.count
end
def industry_jobs
@industry = Industry.find_by(converted_name: params[:converted_name])
@jobs_list = @industry.jobs.all_job.page(params[:page]).per(20)
@result_for_job = @industry.jobs.count
end
def use_variables
@cities = City.all
@industries = Industry.all
@industry = Industry.find(params[:id])
@jobs_list = @industry.jobs.all_job.page(params[:page]).per(20)
@total_job = Job.count
@result_for_job = @industry.jobs.count
end
end
class City < ApplicationRecord
before_save :convert_city
has_many :city_jobs
has_many :jobs, through: :city_jobs
......
class Company < ApplicationRecord
before_save :convert_company
has_many :jobs
def convert_company
self.converted_name = Convert.to_convert("#{name}")
end
end
class Industry < ApplicationRecord
before_save :convert_industry
has_many :industry_jobs
has_many :jobs, through: :industry_jobs
scope :top_industry, -> { joins(:jobs).group(:industry_id).order('count(job_id) DESC').limit(9) }
scope :all_industry, -> { joins(:jobs).group(:industry_id).order('count(job_id) DESC') }
def convert_industry
converted_name = Convert.to_convert("#{name}")
end
def convert_name
name.mb_chars.normalize(:kd).gsub(/[Đđ]/, 'd').gsub(/[^\x00-\x7F]/,'').gsub(/[\W+0-9]/,' ').downcase.to_s.split(' ').join('-')
converted_name = Convert.to_convert_name("#{name}")
end
end
class Job < ApplicationRecord
before_save :convert_job
belongs_to :company
has_many :city_jobs
has_many :cities, through: :city_jobs
......@@ -18,6 +19,10 @@ class Job < ApplicationRecord
scope :limit_job, -> { includes(:cities, :company).order(created_at: :desc).limit(5) }
scope :all_job, -> { limit(20).order(created_at: :desc) }
def convert_job
self.converted_name = Convert.to_convert("#{title}")
end
def company_name
company&.name
end
......
<div class="col-3 remove-decoration">
<%= link_to city_jobs_path(name: city.name) do %>
<%= link_to city_jobs_path(converted_name: city.converted_name) do %>
<div class="border border-dark rounded vn-name">
<div>
<strong><%= city.name %></strong>
......
<div class="col-3 remove-decoration">
<%= link_to city_jobs_path(name: city.convert_name) do %>
<%= link_to city_jobs_path(converted_name: city.convert_name) do %>
<div class="border border-dark rounded international-name">
<div>
<strong><%= city.name %></strong>
......
<div class="col-3 remove-decoration">
<%= link_to industry_jobs_path(industry.id) do %>
<%= link_to industry_jobs_path(converted_name: industry.converted_name) do %>
<div class="border border-dark rounded industry-details">
<div>
<strong><%= industry.name %></strong>
......
......@@ -3,12 +3,10 @@
<div class="job-details">
<div class="title"><strong><%= job.title %></strong></div>
<div class="row">
<div class="col-6">
<% job.cities.each do |city| %>
<%= city.name %>
<% end %>
<div class="col-5">
<%= job.cities.map(&:name).join(' | ') %>
</div>
<div class="col-4 salary">💲 Salary: <%= job.salary %></div>
<div class="col-5 salary">💲 Salary: <%= job.salary %></div>
<div class="col-10 introduction">
<%= job_description(job.description) %><br>
<%= link_to 'Read more..', '#'%>
......
<div class="row">
<div class="row panigation">
<div class="col-12 d-flex justify-content-end paginate-jobs">
<%= paginate @jobs_list, outer_window: 3, window: 2 %>
</div>
......
......@@ -3,9 +3,8 @@
<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: <%= @result_for_job %> jobs</div>
<div class="total-jobs">
<div class="total">Total: <strong><%= @result_for_job %></strong> jobs in <strong><%= @city.name %></strong></div>
</div>
<%= render "jobs/pagination" %>
<div class="job-list">
......
......@@ -3,9 +3,8 @@
<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: <%= @result_for_job %> jobs</div>
<div class="total-jobs">
<div class="total">Total: <strong><%= @result_for_job %></strong> jobs in <strong><%= @industry.name %></strong></div>
</div>
<%= render "jobs/pagination" %>
<div class="job-list">
......
<div class="col-4">
<div class="row-table border border-dark rounded city-list">
<%= link_to city_jobs_path(name: city.name) do %>
<%= link_to city_jobs_path(converted_name: city.converted_name) do %>
<div class="city-name"><strong><%= city.name %></strong></div>
<div class="count-job"><%= city.jobs.count %></div>
<% end %>
......
<div class="col-4">
<div class="row-table border border-dark rounded industry-list">
<%= link_to industry_jobs_path(industry.id) do %>
<%= link_to industry_jobs_path(converted_name: industry.converted_name) do %>
<div class="industry-name"><strong><%= industry.name %></strong></div>
<div class="count-job"><%= industry.jobs.count %></div>
<% end %>
......
......@@ -5,9 +5,7 @@
<div><%= job.company_name %></div>
<div class="salary">💲 Salary: <%= job.salary %></div>
<div>
<% job.cities.each do |city| %>
<%= city.name %>
<% end %>
<%= job.cities.map(&:name).join(' | ') %>
</div>
<div class="row">
<div class="col-10 introduction">
......
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
resources :jobs
get 'jobs/city/:name', to: 'jobs#city_jobs', as: :city_jobs
get 'jobs/industry/:id', to: 'jobs#industry_jobs', as: :industry_jobs
get 'jobs/city/:converted_name', to: 'jobs#city_jobs', as: :city_jobs
get 'jobs/industry/:converted_name', to: 'jobs#industry_jobs', as: :industry_jobs
resources :top_pages
resources :industries
......
......@@ -8,6 +8,8 @@ class CreateJobs < ActiveRecord::Migration[5.2]
t.string :experience
t.string :expiration_date
t.bigint :company_id
t.string :converted_name
t.timestamps
end
end
......
......@@ -3,6 +3,7 @@ class CreateCities < ActiveRecord::Migration[5.2]
create_table :cities, :options => 'COLLATE=utf8_general_ci' do |t|
t.string :name
t.boolean :location
t.string :converted_name
t.timestamps
end
......
......@@ -2,6 +2,7 @@ class CreateIndustries < ActiveRecord::Migration[5.2]
def change
create_table :industries, :options => 'COLLATE=utf8_general_ci' do |t|
t.string :name
t.string :converted_name
t.timestamps
end
......
......@@ -4,6 +4,7 @@ class CreateCompanies < ActiveRecord::Migration[5.2]
t.string :name
t.text :address
t.text :introduction
t.string :converted_name
t.timestamps
end
......
......@@ -10,11 +10,12 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_07_23_071239) do
ActiveRecord::Schema.define(version: 2020_07_15_035356) do
create_table "cities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name"
t.boolean "location"
t.string "converted_name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
......@@ -30,6 +31,7 @@ ActiveRecord::Schema.define(version: 2020_07_23_071239) do
t.string "name"
t.text "address"
t.text "introduction"
t.string "converted_name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
......@@ -50,6 +52,7 @@ ActiveRecord::Schema.define(version: 2020_07_23_071239) do
create_table "industries", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name"
t.string "converted_name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
......@@ -79,6 +82,7 @@ ActiveRecord::Schema.define(version: 2020_07_23_071239) do
t.string "experience"
t.string "expiration_date"
t.bigint "company_id"
t.string "converted_name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
......
......@@ -3,6 +3,7 @@ class Crawler
VIETNAM = 0
FOREIGN = 1
def initialize(logger, url)
@logger = logger
@url = url
......@@ -74,7 +75,6 @@ class Crawler
expiration_date: expiration_date,
description: description,
company_id: company.id)
city_relationship(row, job)
industry_relationship(row, job)
end
......
......@@ -59,6 +59,12 @@ class CSVImporter
salary: salary,
company_id: company_id)
job = Job.find_or_create_by!(title: title_job,
description: description_job,
level: level,
salary: salary,
company_id: company.id)
industry_name = row["category"]
industries_relationship = Industry.where(name: industry_name)
next if industries_relationship.blank?
......
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