Commit 4bffefa9 by nnnghia98

show data on top page

parent c9abce78
...@@ -24,6 +24,7 @@ gem 'kaminari' ...@@ -24,6 +24,7 @@ gem 'kaminari'
gem 'sunspot_rails' gem 'sunspot_rails'
gem 'sunspot_solr' gem 'sunspot_solr'
gem 'devise' gem 'devise'
gem 'activerecord-import'
# Use Redis adapter to run Action Cable in production # Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0' # gem 'redis', '~> 4.0'
# Use Active Model has_secure_password # Use Active Model has_secure_password
......
...@@ -45,6 +45,8 @@ GEM ...@@ -45,6 +45,8 @@ GEM
activerecord (6.0.1) activerecord (6.0.1)
activemodel (= 6.0.1) activemodel (= 6.0.1)
activesupport (= 6.0.1) activesupport (= 6.0.1)
activerecord-import (1.0.3)
activerecord (>= 3.2)
activestorage (6.0.1) activestorage (6.0.1)
actionpack (= 6.0.1) actionpack (= 6.0.1)
activejob (= 6.0.1) activejob (= 6.0.1)
...@@ -256,6 +258,7 @@ PLATFORMS ...@@ -256,6 +258,7 @@ PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
activerecord-import
bootsnap (>= 1.4.2) bootsnap (>= 1.4.2)
byebug byebug
capybara (>= 2.15) capybara (>= 2.15)
......
// Place all the styles related to the Cities controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the companies controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the industries controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the Jobs controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class CitiesController < ApplicationController
def index
@cities = City.all
end
def import
City.cities_import
end
end
class CompaniesController < ApplicationController
def index
end
def import
end
end
class IndustriesController < ApplicationController
def index
@industries = Industry.all
end
def import
Industry.industries_import
end
end
class JobsController < ApplicationController
def index
@jobs = Job.all
end
def import
Job.jobs_import
end
end
class StaticPagesController < ApplicationController class StaticPagesController < ApplicationController
def top_page def top_page
@cities = City.all
@industries = Industry.all
end end
def favorite def favorite
......
module CitiesHelper
end
module CompaniesHelper
end
module IndustriesHelper
end
module JobsHelper
end
# In database
# t.string :name, unique: true
# t.string :region
require "csv"
require "activerecord-import"
# require "activerecord -import/active_record/adapters/mysql_adapter"
class City < ApplicationRecord class City < ApplicationRecord
def self.cities_import
cities = []
columns = [:name, :region]
CSV.foreach(Rails.root.join("lib", "jobss.csv"), headers: true) do |row|
cities << {name: row["company province"], region: "Việt Nam"}
end
City.import columns, cities, on_duplicate_key_ignore: true
end
end end
# In db
# t.string :name
# t.string :email, unique: true
# t.text :description
# t.string :address
# add_index :industries, :name, unique: true
require "csv"
require "activerecord-import"
# require "activerecord -import/active_record/adapters/mysql_adapter"
class Company < ApplicationRecord class Company < ApplicationRecord
def self.companies_import
companies = []
columns = [:name, :email, :address]
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"]}
end
City.import columns, companies, on_duplicate_key_ignore: true
end
end end
# In db
# t.string :name
require "csv"
require "activerecord-import"
# require "activerecord -import/active_record/adapters/mysql_adapter"
class Industry < ApplicationRecord class Industry < ApplicationRecord
def self.industries_import
industries = []
columns = [:name]
CSV.foreach(Rails.root.join("lib", "jobss.csv"), headers: true) do |row|
industries << {name: row["category"]}
end
Industry.import columns, industries, on_duplicate_key_ignore: true
end
end end
# In database
# t.string :title
# t.string :level
# t.string :salary
# t.string :other_salary
# t.text :description
# t.text :short_des
# t.text :requirement
# t.integer :category
# t.datetime :post_date
# t.datetime :expiration_date
# t.references :company, null: false, foreign_key: true
require "csv"
require "activerecord-import"
# require "activerecord -import/active_record/adapters/mysql_adapter"
class Job < ApplicationRecord class Job < ApplicationRecord
belongs_to :company belongs_to :company
def self.jobs_import
jobs = []
columns = [:title, :level, :salary, :description, :short_des, :requirement, :category]
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"]}
end
Job.import columns, jobs
end
end end
<li class="list-group-item"><%= city.name %></li>
<h1>Cities#import</h1>
<p>Find me in app/views/cities/import.html.erb</p>
<table class="table">
<thead>
<tr>
<th scope="col">name</th>
<th scope="col">region</th>
</tr>
</thead>
<tbody>
<% @cities.each do |city| %>
<tr>
<td><%= city.name %></td>
<td><%= city.region %></td>
</tr>
<% end %>
</tbody>
</table>
<h1>Companies#import</h1>
<p>Find me in app/views/companies/import.html.erb</p>
<h1>Companies#index</h1>
<p>Find me in app/views/companies/index.html.erb</p>
<li class="list-group-item"><%= industry.name %></li>
<h1>Industries#import</h1>
<p>Find me in app/views/industries/import.html.erb</p>
<table class="table">
<thead>
<tr>
<th scope="col">name</th>
</tr>
</thead>
<tbody>
<% @industries.each do |industry| %>
<tr>
<td><%= industry.name %></td>
</tr>
<% end %>
</tbody>
</table>
<table class="table">
<thead>
<tr>
<th scope="col">title</th>
<th scope="col">level</th>
<th scope="col">salary</th>
</tr>
</thead>
<tbody>
<% @jobs.each do |job| %>
<tr>
<td><%= job.title %></td>
<td><%= job.level %></td>
<td><%= job.salary %></td>
</tr>
<% end %>
</tbody>
</table>
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<nav> <nav>
<ul> <ul>
<li>ZIGExN VeNtura</li> <li>ZIGExN VeNtura</li>
<li><%= Time.now.year %></li> <li><%= Time.current.year %></li>
</ul> </ul>
</nav> </nav>
</footer> </footer>
...@@ -3,20 +3,12 @@ ...@@ -3,20 +3,12 @@
<%= link_to image_tag("venjob_logo.png", alt: "VeNJOB Logo") , root_path, id: "logo" %> <%= link_to image_tag("venjob_logo.png", alt: "VeNJOB Logo") , root_path, id: "logo" %>
<nav> <nav>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<ul class="list"> <ul class="list-inline-item">
<li class="list-item"> <li class="list-inline-item"><%= link_to "Login", "#" %></li>
<li class="list-inline-item"><%= link_to "Login", "#" %></li> <li class="list-inline-item"><%= link_to "Register", "#" %></li>
<li class="list-inline-item"><%= link_to "Register", "#" %></li> <li class="list-inline-item"><%= link_to "Favorite", favorite_path %></li>
</li> <li class="list-inline-item"><%= link_to "History", history_path %></li>
<li class="list-item">
<li class="list-inline-item"><%= link_to "Favorite", favorite_path %></li>
<li class="list-inline-item"><%= link_to "History", history_path %></li>
</li>
</ul> </ul>
<!-- <li><%= link_to "Login", "#" %></li>
<li><%= link_to "Register", "#" %></li>
<li><%= link_to "Favorite", favorite_path %></li>
<li><%= link_to "History", history_path %></li> -->
</ul> </ul>
</nav> </nav>
</div> </div>
......
...@@ -2,5 +2,26 @@ ...@@ -2,5 +2,26 @@
<div class="container"> <div class="container">
<div class="banner"> <div class="banner">
<img src="banner.png" alt="Banner">
</div>
<div class="search"></div>
<div class="lastest_jobs"></div>
<div class="top_cities">
<h3>Top cities</h3>
<ul class="list-group list-group-horizontal">
<%= render partial: "cities/city", collection: @cities %>
</ul>
</div>
<div class="top_industries">
<h3>Top industries</h3>
<ul class="list-group list-group-horizontal">
<%= render partial: "industries/industry", collection: @industries %>
</ul>
</div> </div>
</div> </div>
Rails.application.routes.draw do Rails.application.routes.draw do
get 'companies/index'
get 'companies/import'
get "industries/index"
get "industries/import"
resources :industries do
collection {post :import}
end
get "cities/index"
get "cities/import"
resources :cities do
collection {post :import}
end
get "jobs/index"
get "jobs/import"
resources :jobs do
collection {post :import}
end
devise_for :users devise_for :users
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
root "static_pages#top_page" root "static_pages#top_page"
......
class CreateIndustries < ActiveRecord::Migration[6.0] class CreateIndustries < ActiveRecord::Migration[6.0]
def change def change
create_table :industries do |t| create_table :industries do |t|
t.string :name t.string :name, unique: true
t.timestamps t.timestamps
end end
add_index :industries, :name, unique: true
end end
end end
...@@ -17,6 +17,7 @@ ActiveRecord::Schema.define(version: 2019_11_26_083335) do ...@@ -17,6 +17,7 @@ ActiveRecord::Schema.define(version: 2019_11_26_083335) do
t.string "region" t.string "region"
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 ["name"], name: "index_cities_on_name", unique: true
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|
...@@ -35,6 +36,7 @@ ActiveRecord::Schema.define(version: 2019_11_26_083335) do ...@@ -35,6 +36,7 @@ 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.index ["email"], name: "index_companies_on_email", unique: true
end end
create_table "crawl_urls", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "crawl_urls", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
...@@ -49,6 +51,7 @@ ActiveRecord::Schema.define(version: 2019_11_26_083335) do ...@@ -49,6 +51,7 @@ ActiveRecord::Schema.define(version: 2019_11_26_083335) do
t.string "name" t.string "name"
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 ["name"], name: "index_industries_on_name", unique: true
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|
......
,nghiann,devops-OptiPlex-3020,29.11.2019 16:15,file:///home/nghiann/.config/libreoffice/4;
\ No newline at end of file
This diff is collapsed. Click to expand it.
require 'test_helper'
class CitiesControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get cities_index_url
assert_response :success
end
test "should get import" do
get cities_import_url
assert_response :success
end
end
require 'test_helper'
class CompaniesControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get companies_index_url
assert_response :success
end
test "should get import" do
get companies_import_url
assert_response :success
end
end
require 'test_helper'
class IndustriesControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get industries_index_url
assert_response :success
end
test "should get import" do
get industries_import_url
assert_response :success
end
end
require 'test_helper'
class JobsControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get jobs_index_url
assert_response :success
end
test "should get import" do
get jobs_import_url
assert_response :success
end
end
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
region: MyString
two:
name: MyString
region: MyString
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
email: MyString
description: MyText
address: MyString
two:
name: MyString
email: MyString
description: MyText
address: MyString
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
user: one
job: one
applied_at: 2019-11-26 15:31:51
relation: 1
two:
user: two
job: two
applied_at: 2019-11-26 15:31:51
relation: 1
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
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