change handle in controller to handle in model

parent f6afc562
Pipeline #796 failed with stages
in 0 seconds
class CitiesController < ApplicationController class CitiesController < ApplicationController
def index def index
@cities_vietnam = City.all_city.where('location = 1') @cities_vietnam = City.all_city.vietnam
@cities_international = City.all_city.where('location = 0') @cities_international = City.all_city.international
end end
end end
...@@ -2,10 +2,11 @@ class City < ApplicationRecord ...@@ -2,10 +2,11 @@ class City < ApplicationRecord
has_many :city_jobs has_many :city_jobs
has_many :jobs, through: :city_jobs has_many :jobs, through: :city_jobs
scope :all_city, -> { joins(:jobs).group(:city_id).order('count(job_id) DESC') }
scope :vietnam, -> { where('location = 1') }
scope :international, -> { where('location = 0') }
def self.top_city def self.top_city
joins(:jobs).group(:city_id).order('count(job_id) DESC').limit(9) joins(:jobs).group(:city_id).order('count(job_id) DESC').limit(9)
end end
def self.all_city
joins(:jobs).group(:city_id).order('count(job_id) DESC')
end
end end
...@@ -15,8 +15,9 @@ class JobParser ...@@ -15,8 +15,9 @@ class JobParser
links = info.css('div.caption a.company-name').map { |link| link['href'] } links = info.css('div.caption a.company-name').map { |link| link['href'] }
links.each do |link| links.each do |link|
next if link == 'javascript:void(0);' next if link == 'javascript:void(0);'
page = Nokogiri::HTML(URI.open(URI.escape(link)))
name = page.search('p.name')&.text page = Nokogiri::HTML(URI.open(URI.escape(link)))
name = page.search('p.name')&.text
next if name.blank? next if name.blank?
address = page.css('div.content p').children[1]&.text address = page.css('div.content p').children[1]&.text
......
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