Commit 8e2dcc16 by nnnghia98

update controllers

parent 5a71084e
...@@ -5,5 +5,6 @@ class CitiesController < ApplicationController ...@@ -5,5 +5,6 @@ class CitiesController < ApplicationController
def import def import
City.cities_import City.cities_import
redirect_to root_path
end end
end end
...@@ -5,5 +5,6 @@ class IndustriesController < ApplicationController ...@@ -5,5 +5,6 @@ class IndustriesController < ApplicationController
def import def import
Industry.industries_import Industry.industries_import
redirect_to root_path
end end
end end
...@@ -5,5 +5,6 @@ class JobsController < ApplicationController ...@@ -5,5 +5,6 @@ class JobsController < ApplicationController
def import def import
Job.jobs_import Job.jobs_import
redirect_to jobs_index_path
end end
end end
...@@ -11,12 +11,14 @@ require "activerecord-import" ...@@ -11,12 +11,14 @@ require "activerecord-import"
# require "activerecord -import/active_record/adapters/mysql_adapter" # require "activerecord -import/active_record/adapters/mysql_adapter"
class Company < ApplicationRecord class Company < ApplicationRecord
has_many :jobs, dependent: :destroy
def self.companies_import def self.companies_import
companies = [] companies = []
columns = [:name, :email, :address] columns = [:name, :email, :address, :company_code]
CSV.foreach(Rails.root.join("lib", "jobss.csv"), headers: true) do |row| CSV.foreach(Rails.root.join("lib", "jobss.csv"), headers: true) do |row|
companies << {name: row["company name"], email: row["contact email"], address: row["company address"]} companies << {name: row["company name"], email: row["contact email"], address: row["company address"], company_code: row["company id"]}
end end
Company.import columns, companies, on_duplicate_key_ignore: true Company.import columns, companies, on_duplicate_key_ignore: true
......
...@@ -20,10 +20,10 @@ class Job < ApplicationRecord ...@@ -20,10 +20,10 @@ class Job < ApplicationRecord
def self.jobs_import def self.jobs_import
jobs = [] jobs = []
columns = [:title, :level, :salary, :description, :short_des, :requirement, :category] columns = [:title, :level, :salary, :description, :short_des, :requirement, :category, :company_id]
CSV.foreach(Rails.root.join("lib", "jobss.csv"), headers: true) do |row| CSV.foreach(Rails.root.join("lib", "jobss.csv"), headers: true) do |row|
jobs << {title: row["name"], level: row["level"], salary: row["salary"], description: row["description"], short_des: row["benifit"], requirement: row["requirement"], category: row["type"]} jobs << {title: row["name"], level: row["level"], salary: row["salary"], description: row["description"], short_des: row["benefit"], requirement: row["requirement"], category: row["type"]}
end end
Job.import columns, jobs Job.import columns, jobs
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<th scope="col">company name</th> <th scope="col">company name</th>
<th scope="col">contact email</th> <th scope="col">contact email</th>
<th scope="col">company address</th> <th scope="col">company address</th>
<th scope="col">company code</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
...@@ -14,6 +15,7 @@ ...@@ -14,6 +15,7 @@
<td><%= company.name %></td> <td><%= company.name %></td>
<td><%= company.email %></td> <td><%= company.email %></td>
<td><%= company.address %></td> <td><%= company.address %></td>
<td><%= company.company_code %></td>
</tr> </tr>
<% end %> <% end %>
</tbody> </tbody>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<thead> <thead>
<tr> <tr>
<th scope="col">title</th> <th scope="col">title</th>
<th scope="col">level</th> <th scope="col">short description</th>
<th scope="col">salary</th> <th scope="col">salary</th>
</tr> </tr>
</thead> </thead>
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<% @jobs.each do |job| %> <% @jobs.each do |job| %>
<tr> <tr>
<td><%= job.title %></td> <td><%= job.title %></td>
<td><%= job.level %></td> <td><%= job.short_des %></td>
<td><%= job.salary %></td> <td><%= job.salary %></td>
</tr> </tr>
<% end %> <% end %>
......
...@@ -11,7 +11,7 @@ class CreateJobs < ActiveRecord::Migration[6.0] ...@@ -11,7 +11,7 @@ class CreateJobs < ActiveRecord::Migration[6.0]
t.integer :category t.integer :category
t.datetime :post_date t.datetime :post_date
t.datetime :expiration_date t.datetime :expiration_date
t.references :company, null: false, foreign_key: true t.references :company, foreign_key: true
t.timestamps t.timestamps
end end
......
class CreateUserJobs < ActiveRecord::Migration[6.0] class CreateUserJobs < ActiveRecord::Migration[6.0]
def change def change
create_table :user_jobs do |t| create_table :user_jobs do |t|
t.references :user, null: false, foreign_key: true t.references :user, foreign_key: true
t.references :job, null: false, foreign_key: true t.references :job, foreign_key: true
t.datetime :applied_at t.datetime :applied_at
t.datetime :viewed_at t.datetime :viewed_at
t.datetime :favorited_at t.datetime :favorited_at
......
class CreateCityJobs < ActiveRecord::Migration[6.0] class CreateCityJobs < ActiveRecord::Migration[6.0]
def change def change
create_table :city_jobs do |t| create_table :city_jobs do |t|
t.references :city, null: false, foreign_key: true t.references :city, foreign_key: true
t.references :job, null: false, foreign_key: true t.references :job, foreign_key: true
t.timestamps t.timestamps
end end
......
class CreateIndustryJobs < ActiveRecord::Migration[6.0] class CreateIndustryJobs < ActiveRecord::Migration[6.0]
def change def change
create_table :industry_jobs do |t| create_table :industry_jobs do |t|
t.references :industry, null: false, foreign_key: true t.references :industry, foreign_key: true
t.references :job, null: false, foreign_key: true t.references :job, foreign_key: true
t.timestamps t.timestamps
end end
......
class AddCompanyCodeToCompany < ActiveRecord::Migration[6.0]
def change
add_column :companies, :company_code, :string, unique: true
end
end
class AddIndexToCompanyCode < ActiveRecord::Migration[6.0]
def change
add_index :companies, :company_code, unique: true
end
end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# 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: 2019_11_26_083335) do ActiveRecord::Schema.define(version: 2019_12_02_023440) do
create_table "cities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "cities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name" t.string "name"
...@@ -21,8 +21,8 @@ ActiveRecord::Schema.define(version: 2019_11_26_083335) do ...@@ -21,8 +21,8 @@ ActiveRecord::Schema.define(version: 2019_11_26_083335) do
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=utf8", force: :cascade do |t|
t.bigint "city_id", null: false t.bigint "city_id"
t.bigint "job_id", null: false t.bigint "job_id"
t.datetime "created_at", precision: 6, null: false t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false
t.index ["city_id"], name: "index_city_jobs_on_city_id" t.index ["city_id"], name: "index_city_jobs_on_city_id"
...@@ -36,6 +36,8 @@ ActiveRecord::Schema.define(version: 2019_11_26_083335) do ...@@ -36,6 +36,8 @@ ActiveRecord::Schema.define(version: 2019_11_26_083335) do
t.string "address" t.string "address"
t.datetime "created_at", precision: 6, null: false t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false
t.string "company_code"
t.index ["company_code"], name: "index_companies_on_company_code", unique: true
t.index ["email"], name: "index_companies_on_email", unique: true t.index ["email"], name: "index_companies_on_email", unique: true
end end
...@@ -55,8 +57,8 @@ ActiveRecord::Schema.define(version: 2019_11_26_083335) do ...@@ -55,8 +57,8 @@ ActiveRecord::Schema.define(version: 2019_11_26_083335) do
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=utf8", force: :cascade do |t|
t.bigint "industry_id", null: false t.bigint "industry_id"
t.bigint "job_id", null: false t.bigint "job_id"
t.datetime "created_at", precision: 6, null: false t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false
t.index ["industry_id"], name: "index_industry_jobs_on_industry_id" t.index ["industry_id"], name: "index_industry_jobs_on_industry_id"
...@@ -74,15 +76,15 @@ ActiveRecord::Schema.define(version: 2019_11_26_083335) do ...@@ -74,15 +76,15 @@ ActiveRecord::Schema.define(version: 2019_11_26_083335) do
t.integer "category" t.integer "category"
t.datetime "post_date" t.datetime "post_date"
t.datetime "expiration_date" t.datetime "expiration_date"
t.bigint "company_id", null: false t.bigint "company_id"
t.datetime "created_at", precision: 6, null: false t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false
t.index ["company_id"], name: "index_jobs_on_company_id" t.index ["company_id"], name: "index_jobs_on_company_id"
end end
create_table "user_jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "user_jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.bigint "user_id", null: false t.bigint "user_id"
t.bigint "job_id", null: false t.bigint "job_id"
t.datetime "applied_at" t.datetime "applied_at"
t.datetime "viewed_at" t.datetime "viewed_at"
t.datetime "favorited_at" t.datetime "favorited_at"
......
,nghiann,devops-OptiPlex-3020,02.12.2019 09:27,file:///home/nghiann/.config/libreoffice/4;
\ No newline at end of file
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