Commit 6d4d7392 by Ngô Trung Hưng

..

parent 4036163b
Pipeline #816 canceled with stages
in 0 seconds
module Slug module Slug
def to_slug(str) def self.to_slug(str)
str = str.to_s.strip.downcase str = str.to_s.strip.downcase
accents = { accents = {
%w[à á ạ ả ã â ầ ấ ậ ẩ ẫ ă ằ ắ ặ ẳ ẵ] => 'a', %w[à á ạ ả ã â ầ ấ ậ ẩ ẫ ă ằ ắ ặ ẳ ẵ] => 'a',
......
...@@ -6,7 +6,7 @@ class JobController < ApplicationController ...@@ -6,7 +6,7 @@ class JobController < ApplicationController
def index def index
model = params[:model].classify.constantize model = params[:model].classify.constantize
obj = model.find(params[:id]) obj = model.find_by(slug: params[:slug])
result(obj) result(obj)
end end
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# Description/Explanation of Person class # Description/Explanation of Person class
class City < ApplicationRecord class City < ApplicationRecord
before_save :convert_to_slug
RANGE = 69 RANGE = 69
has_many :city_jobs has_many :city_jobs
has_many :jobs, through: :city_jobs has_many :jobs, through: :city_jobs
...@@ -14,4 +15,8 @@ class City < ApplicationRecord ...@@ -14,4 +15,8 @@ class City < ApplicationRecord
.order(Arel.sql('count(jobs.id) DESC')) .order(Arel.sql('count(jobs.id) DESC'))
.take(number) .take(number)
end end
def convert_to_slug
self.slug = Slug.to_slug(self.name)
end
end end
...@@ -3,5 +3,10 @@ ...@@ -3,5 +3,10 @@
# Description/Explanation of Person class # Description/Explanation of Person class
class Company < ApplicationRecord class Company < ApplicationRecord
COMPANY_SECURITY = 1 COMPANY_SECURITY = 1
before_save :convert_to_slug
has_many :jobs has_many :jobs
def convert_to_slug
self.slug = Slug.to_slug(self.name)
end
end end
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# Description/Explanation of Person class # Description/Explanation of Person class
class Industry < ApplicationRecord class Industry < ApplicationRecord
before_save :convert_to_slug
has_many :industry_jobs has_many :industry_jobs
has_many :jobs, through: :industry_jobs has_many :jobs, through: :industry_jobs
scope :top_industries, ->(number) do joins(:jobs) scope :top_industries, ->(number) do joins(:jobs)
...@@ -9,4 +10,8 @@ class Industry < ApplicationRecord ...@@ -9,4 +10,8 @@ class Industry < ApplicationRecord
.order(Arel.sql('count(jobs.id) DESC')) .order(Arel.sql('count(jobs.id) DESC'))
.take(number) .take(number)
end end
def convert_to_slug
self.slug = Slug.to_slug(self.name)
end
end end
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<div class="col-lg-3 col-md-4"> <div class="col-lg-3 col-md-4">
<div class="box_cityjobs"> <div class="box_cityjobs">
<div class="box_cityjobs_name"> <div class="box_cityjobs_name">
<%= link_to city.name, jobs_path(model: 'city', id: city.id), class: 'cityjobs_link' %> <%= link_to city.name, jobs_path(model: 'city', slug: city.slug), class: 'cityjobs_link' %>
</div> </div>
<div class="box_cityjobs_count"> <div class="box_cityjobs_count">
<span><%= city.jobs.count %> Công việc</span> <span><%= city.jobs.count %> Công việc</span>
......
...@@ -9,10 +9,10 @@ ...@@ -9,10 +9,10 @@
<div class="box_info_city"> <div class="box_info_city">
<div class="ct_name"> <div class="ct_name">
<!-- <%= link_to city.name, "/jobs/city/#{city.id}" ,class: 'link_ct' %> --> <!-- <%= link_to city.name, "/jobs/city/#{city.id}" ,class: 'link_ct' %> -->
<%= link_to city.name, jobs_path(model: 'city', id: city.id),class: 'link_ct' %> <%= link_to city.name, jobs_path(model: 'city', slug: city.slug),class: 'link_ct' %>
</div> </div>
<div class="ct_jobs_count"> <div class="ct_jobs_count">
<%= link_to "#{city.jobs.count} công việc", jobs_path(model: 'city', id: city.id),class: 'link_ct' %> <%= link_to "#{city.jobs.count} công việc", jobs_path(model: 'city', slug: city.slug),class: 'link_ct' %>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -8,10 +8,10 @@ ...@@ -8,10 +8,10 @@
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12"> <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
<div class="box_info_city"> <div class="box_info_city">
<div class="ct_name"> <div class="ct_name">
<%= link_to industry.name, jobs_path(model: 'industry', id: industry.id), class: 'link_ct' %> <%= link_to industry.name, jobs_path(model: 'industry', slug: industry.slug), class: 'link_ct' %>
</div> </div>
<div class="ct_jobs_count"> <div class="ct_jobs_count">
<%= link_to "#{industry.jobs.count} công việc", jobs_path(model: 'industry', id: industry.id), class: 'link_ct' %> <%= link_to "#{industry.jobs.count} công việc", jobs_path(model: 'industry', slug: industry.slug), class: 'link_ct' %>
</div> </div>
</div> </div>
</div> </div>
......
<div class="col-lg-3 col-md-4"> <div class="col-lg-3 col-md-4">
<div class="box_cityjobs"> <div class="box_cityjobs">
<div class="box_cityjobs_name"> <div class="box_cityjobs_name">
<%= link_to industry.name, jobs_path(model: 'industry', id: industry.id), class: 'cityjobs_link' %> <%= link_to industry.name, jobs_path(model: 'industry', slug: industry.slug), class: 'cityjobs_link' %>
</div> </div>
<div class="box_cityjobs_count"> <div class="box_cityjobs_count">
<span><%= industry.jobs.count %> Công việc</span> <span><%= industry.jobs.count %> Công việc</span>
......
...@@ -6,5 +6,5 @@ Rails.application.routes.draw do ...@@ -6,5 +6,5 @@ Rails.application.routes.draw do
get 'city/index' get 'city/index'
# Search # Search
get 'jobs/:model/:id', to: 'job#index', as: :jobs get 'jobs/:model/:slug', to: 'job#index', as: :jobs
end end
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_07_29_064551) do ActiveRecord::Schema.define(version: 2020_08_05_075807) do
create_table "applied_jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "applied_jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.bigint "user_id" t.bigint "user_id"
t.bigint "job_id" t.bigint "job_id"
t.string "name" t.string "name"
...@@ -24,14 +24,15 @@ ActiveRecord::Schema.define(version: 2020_07_29_064551) do ...@@ -24,14 +24,15 @@ ActiveRecord::Schema.define(version: 2020_07_29_064551) do
t.index ["user_id"], name: "index_applied_jobs_on_user_id" t.index ["user_id"], name: "index_applied_jobs_on_user_id"
end end
create_table "cities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "cities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.string "name" t.string "name"
t.integer "area" t.integer "area"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.string "slug"
end end
create_table "city_jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "city_jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.bigint "job_id" t.bigint "job_id"
t.bigint "city_id" t.bigint "city_id"
t.datetime "created_at", null: false t.datetime "created_at", null: false
...@@ -40,35 +41,37 @@ ActiveRecord::Schema.define(version: 2020_07_29_064551) do ...@@ -40,35 +41,37 @@ ActiveRecord::Schema.define(version: 2020_07_29_064551) do
t.index ["job_id"], name: "index_city_jobs_on_job_id" t.index ["job_id"], name: "index_city_jobs_on_job_id"
end end
create_table "companies", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "companies", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.string "name" t.string "name"
t.string "address" t.string "address"
t.text "short_description" t.text "short_description"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.string "slug"
end end
create_table "favorites", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "favorites", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.integer "user_id" t.integer "user_id"
t.integer "job_id" t.integer "job_id"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
end end
create_table "histories", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "histories", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.integer "user_id" t.integer "user_id"
t.integer "job_id" t.integer "job_id"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
end end
create_table "industries", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "industries", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.string "name" t.string "name"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.string "slug"
end end
create_table "industry_jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "industry_jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.bigint "industry_id" t.bigint "industry_id"
t.bigint "job_id" t.bigint "job_id"
t.datetime "created_at", null: false t.datetime "created_at", null: false
...@@ -77,7 +80,7 @@ ActiveRecord::Schema.define(version: 2020_07_29_064551) do ...@@ -77,7 +80,7 @@ ActiveRecord::Schema.define(version: 2020_07_29_064551) do
t.index ["job_id"], name: "index_industry_jobs_on_job_id" t.index ["job_id"], name: "index_industry_jobs_on_job_id"
end end
create_table "jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.string "name" t.string "name"
t.integer "company_id" t.integer "company_id"
t.string "level" t.string "level"
...@@ -90,7 +93,7 @@ ActiveRecord::Schema.define(version: 2020_07_29_064551) do ...@@ -90,7 +93,7 @@ ActiveRecord::Schema.define(version: 2020_07_29_064551) do
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
end end
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.string "email" t.string "email"
t.string "name" t.string "name"
t.string "password_digest" t.string "password_digest"
......
...@@ -5,7 +5,7 @@ require 'open-uri' ...@@ -5,7 +5,7 @@ require 'open-uri'
# rake task # rake task
namespace :crawler do namespace :crawler do
task populate: :environment do task populate: :environment do
NUMBER_LINK_WILL_BE_CRAWLER = 4 NUMBER_LINK_WILL_BE_CRAWLER = 7
Company.find_or_create_by(name: 'Bảo mật') do |company| Company.find_or_create_by(name: 'Bảo mật') do |company|
company.address = 'Vui lòng xem trong mô tả công việc' company.address = 'Vui lòng xem trong mô tả công việc'
company.short_description = 'Vui lòng xem trong mô tả công việc' company.short_description = 'Vui lòng xem trong mô tả công việc'
......
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