Create Job list and Job detail

parent 1ca2bdf3
......@@ -121,5 +121,15 @@
border: 2px solid #006080;
border-radius: 12px;
text-align: center;
font-size: 32px;
font-size: 20px;
font-family: Bookman, URW Bookman L, serif;
}
.job-details .title a {
color: black;
text-decoration: none;
}
.job-details .title a:hover {
color: #e6b800;
transition: 1s;
text-decoration: none;
}
......@@ -2,8 +2,4 @@ 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 CitiesController < ApplicationController
VIETNAM = 1
FOREIGN = 0
def index
@cities_vietnam = City.location(VIETNAM)
@cities_international = City.location(FOREIGN)
@vietnam = City.location(City::VIETNAM)
@international = City.location(City::FOREIGN)
end
end
......@@ -17,6 +17,10 @@ class JobsController < ApplicationController
@result_for_job = @industry.jobs.count
end
def access_jobs
@job_details = Job.find(params[:id])
end
def use_variables
@cities = City.all
@industries = Industry.all
......
......@@ -3,14 +3,13 @@ class City < ApplicationRecord
has_many :city_jobs
has_many :jobs, through: :city_jobs
VIETNAM = 1
FOREIGN = 0
scope :top_city, -> { joins(:jobs).group(:city_id).order('count(job_id) DESC').limit(9) }
scope :location, ->(number) { joins(:jobs).group(:city_id).order('count(job_id) DESC').where(location: number) }
def convert_city
converted_name = Convert.to_convert("#{name}")
end
def convert_name
converted_name = Convert.to_convert_name("#{name}")
self.converted_name = Convert.to_convert("#{name} #{rand(10000)}")
end
end
......@@ -3,6 +3,6 @@ class Company < ApplicationRecord
has_many :jobs
def convert_company
self.converted_name = Convert.to_convert("#{name}")
self.converted_name = Convert.to_convert("#{name} #{rand(10000)}")
end
end
......@@ -7,10 +7,6 @@ class Industry < ApplicationRecord
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
converted_name = Convert.to_convert_name("#{name}")
self.converted_name = Convert.to_convert("#{name} #{rand(10000)}")
end
end
......@@ -20,7 +20,7 @@ class Job < ApplicationRecord
scope :all_job, -> { all.order(created_at: :desc) }
def convert_job
converted_name = Convert.to_convert("#{title}")
converted_name = Convert.to_convert("#{title} #{rand(10000)}")
end
def company_name
......
<div class="col-3 remove-decoration">
<%= link_to city_jobs_path(converted_name: city.convert_name) do %>
<%= link_to city_jobs_path(converted_name: city.converted_name) do %>
<div class="border border-dark rounded international-name">
<div>
<strong><%= city.name %></strong>
......
......@@ -14,13 +14,13 @@
<div class="city-banner rounded vietnam-area">Việt Nam</div>
<div class="city-vietnam">
<div class="row">
<%= render partial: "vietnam", collection: @cities_vietnam, as: :city %>
<%= render partial: "vietnam", collection: @vietnam, as: :city %>
</div>
</div>
<div class="city-banner rounded international-area">International</div>
<div class="city-international">
<div class="row">
<%= render partial: "international", collection: @cities_international, as: :city %>
<%= render partial: "international", collection: @international, as: :city %>
</div>
</div>
</div>
<% if job.cities.present? %>
<div class="border border-dark rounded">
<div class="job-details">
<div class="title"><strong><%= job.title %></strong></div>
<div class="row">
<div class="col-5">
<%= job.cities.map(&:name).join(' | ') %>
</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>
<div class="title">
<%= link_to job_detail_path(job.id) do %><strong>
<%= job.title %></strong>
<% end %>
</div>
<div class="row">
<div class="col-5">
<%= job.cities.map(&:name).join(' | ') %>
</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>
</div>
<button type="button" class="btn btn-success" id="button-follow">♥ Favorite</button>
</div>
</div>
......
<div class="container">
<%= @job_details.title %>
</div>
<% if job.cities.present? %>
<div class="border border-dark rounded">
<div class="job-details">
<div class="title"><strong><%= job.title %></strong></div>
<div class="title">
<%= link_to job_detail_path(job.id) do %><strong>
<%= job.title %></strong>
<% end %>
</div>
<div><%= job.company_name %></div>
<div class="salary">💲 Salary: <%= job.salary %></div>
<div>
......
......@@ -3,6 +3,7 @@ Rails.application.routes.draw do
resources :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
get 'detail/:id', to: 'jobs#access_jobs', as: :job_detail
resources :top_pages
resources :industries
......
......@@ -20,13 +20,11 @@ class Crawler
data_city.each do |name_city|
if City.find_by(id: 70)
city = City.find_or_create_by!(name: name_city) do |city|
city.location = 0
end
city = City.create!(name: name_city,
location: 0)
else
city = City.find_or_create_by!(name: name_city) do |city|
city.location = 1
end
city = City.create!(name: name_city,
location: 1)
end
end
end
......@@ -47,9 +45,7 @@ class Crawler
cities_relationship = City.where(name: location_relationship)
city_job_relationship = CityJob.where(job_id: job.id ,city_id: cities_relationship.ids)
if city_job_relationship.blank?
job.cities << cities_relationship
end
job.cities << cities_relationship if city_job_relationship.blank?
end
def industry_relationship(row, job)
......@@ -57,9 +53,7 @@ class Crawler
industries_relationship = Industry.where(name: industry_relationship)
industry_job_relationship = IndustryJob.where(job_id: job.id, industry_id: industries_relationship.ids)
if industry_job_relationship.blank?
job.industries << industries_relationship
end
job.industries << industries_relationship if industry_job_relationship.blank?
end
def create_job(title, link_page, row, company)
......@@ -76,6 +70,7 @@ class Crawler
expiration_date: expiration_date,
description: description,
company_id: company.id)
city_relationship(row, job)
industry_relationship(row, job)
end
......@@ -88,14 +83,14 @@ class Crawler
begin
next if link == 'javascript:void(0);'
page = Nokogiri::HTML(URI.open(URI.escape(link)))
name = page.search('p.name')&.text&.strip
name = page.search('p.name')&.text
next if name.blank?
address = page.css('div.content p').children[1]&.text
introduction = page.css('div.main-about-us').text
Company.find_or_create_by!(name: name,
address: address,
introduction: introduction)
address: address,
introduction: introduction)
rescue StandardError => e
@logger.error e.message
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