Commit bf41bbb7 by Mai Hoang Thai Ha

Create top page ID1 (display some jobs from database)

parent 940cdc19
...@@ -5,8 +5,8 @@ ruby '3.0.1' ...@@ -5,8 +5,8 @@ ruby '3.0.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.3', '>= 6.1.3.2' gem 'rails', '~> 6.1.3', '>= 6.1.3.2'
# Use sqlite3 as the database for Active Record # Use mysql2 as the database for Active Record
gem 'sqlite3', '~> 1.4' gem 'mysql2', '~> 0.5'
# Use Puma as the app server # Use Puma as the app server
gem 'puma', '~> 5.0' gem 'puma', '~> 5.0'
# Use SCSS for stylesheets # Use SCSS for stylesheets
......
...@@ -108,6 +108,7 @@ GEM ...@@ -108,6 +108,7 @@ GEM
minitest (5.14.4) minitest (5.14.4)
msgpack (1.4.2) msgpack (1.4.2)
multi_xml (0.6.0) multi_xml (0.6.0)
mysql2 (0.5.3)
nio4r (2.5.7) nio4r (2.5.7)
nokogiri (1.11.7-x86_64-linux) nokogiri (1.11.7-x86_64-linux)
racc (~> 1.4) racc (~> 1.4)
...@@ -211,7 +212,6 @@ GEM ...@@ -211,7 +212,6 @@ GEM
actionpack (>= 4.0) actionpack (>= 4.0)
activesupport (>= 4.0) activesupport (>= 4.0)
sprockets (>= 3.0.0) sprockets (>= 3.0.0)
sqlite3 (1.4.2)
temple (0.8.2) temple (0.8.2)
thor (1.1.0) thor (1.1.0)
tilt (2.0.10) tilt (2.0.10)
...@@ -252,6 +252,7 @@ DEPENDENCIES ...@@ -252,6 +252,7 @@ DEPENDENCIES
httparty (~> 0.18.1) httparty (~> 0.18.1)
jbuilder (~> 2.7) jbuilder (~> 2.7)
listen (~> 3.3) listen (~> 3.3)
mysql2 (~> 0.5)
nokogiri (~> 1.11, >= 1.11.7) nokogiri (~> 1.11, >= 1.11.7)
pry-nav (~> 0.3.0) pry-nav (~> 0.3.0)
pry-rails (~> 0.3.9) pry-rails (~> 0.3.9)
...@@ -263,7 +264,6 @@ DEPENDENCIES ...@@ -263,7 +264,6 @@ DEPENDENCIES
selenium-webdriver selenium-webdriver
slim-rails (~> 3.2) slim-rails (~> 3.2)
spring spring
sqlite3 (~> 1.4)
turbolinks (~> 5) turbolinks (~> 5)
tzinfo-data tzinfo-data
web-console (>= 4.1.0) web-console (>= 4.1.0)
......
...@@ -74,4 +74,128 @@ footer { ...@@ -74,4 +74,128 @@ footer {
margin-left: 15px; margin-left: 15px;
} }
} }
}
// Top page
// search
// latest-job
.latest-job {
h2 {
margin-bottom: 30px;
}
h2::after {
content: "";
display: block;
border-bottom: 1px solid rgba(0, 0, 0, 0.3);
}
.job-item {
font-size: 14px;
.job-title {
text-decoration: none;
color: black;
font-size: 20px;
font-weight: 500;
}
.job-caption {
line-height: 18px;
.job-company {
text-decoration: none;
font-size: 14px;
color: $gray-700;
}
.job-salary {
color: #008563;
margin: 0;
}
.job-locations {
ul {
list-style: none;
margin: 0 0 6px 0;
padding: 0;
color: $gray-700;
}
}
.job-desc {
overflow: hidden;
text-overflow: ellipsis;
line-height: 18px;
-webkit-line-clamp: 2;
height: 36px;
display: -webkit-box;
-webkit-box-orient: vertical;
}
}
}
.job-item::after {
content: "";
display: block;
margin-top: 10px;
border-bottom: 1px solid rgba(0, 0, 0, 0.3);
}
.job-item:last-child::after{
border-bottom: none;
}
}
// top_cities
.top_cities {
h2 {
margin-bottom: 30px;
}
h2::after {
content: "";
display: block;
border-bottom: 1px solid rgba(0, 0, 0, 0.3);
}
.city-item {
margin-bottom: 12px;
a {
font-size: 18px;
text-decoration: none;
color: #287ab9;
margin: 10px 0;
}
}
.all-cities-btn {
color: #287ab9;
font-size: 20px;
text-decoration: none;
}
.all-cities-btn:hover {
text-decoration: underline;
}
}
// top_industries
.top_industries {
h2 {
margin-bottom: 30px;
}
h2::after {
content: "";
display: block;
border-bottom: 1px solid rgba(0, 0, 0, 0.3);
}
.industry-item {
margin-bottom: 12px;
a {
font-size: 18px;
text-decoration: none;
color: #287ab9;
margin: 10px 0;
}
}
.all-industries-btn {
color: #287ab9;
font-size: 20px;
text-decoration: none;
}
.all-industries-btn:hover {
text-decoration: underline;
}
} }
\ No newline at end of file
class TopController < ApplicationController class TopController < ApplicationController
def index def index
@latest_jobs = Job.order(updated_at: :desc).limit(5)
@top_cities = City.all.map { |city| [city, city.jobs.count] }.sort_by(&:second).reverse.take(9)
@top_industries = Industry.all.map { |industry| [industry, industry.jobs.count] }.sort_by(&:second).reverse.take(9)
end end
def create
end
end end
module ApplicationHelper module ApplicationHelper
def full_title(page_title = '')
base_title = 'VenJob'
if page_title.empty?
base_title
else
page_title + " | " + base_title
end
end
end end
...@@ -2,8 +2,7 @@ doctype html ...@@ -2,8 +2,7 @@ doctype html
html html
head head
title title
| hi =full_title(yield(:title))
- # <%= full_title(yield(:title))
meta[name="viewport" content="width=device-width,initial-scale=1" charset="utf-8"] meta[name="viewport" content="width=device-width,initial-scale=1" charset="utf-8"]
= csrf_meta_tags = csrf_meta_tags
= csp_meta_tag = csp_meta_tag
...@@ -12,6 +11,6 @@ html ...@@ -12,6 +11,6 @@ html
= render 'layouts/shim' = render 'layouts/shim'
body body
= render 'layouts/header' = render 'layouts/header'
.container .container-fluid
= yield = yield
= render 'layouts/footer' = render 'layouts/footer'
\ No newline at end of file
.latest-job.mb-5
.container
h2
| Latest jobs
- @latest_jobs.each do |job|
.job-item.mb-4
= link_to job.title, "#", class: "job-title"
.job-caption
= link_to job.company.name, "#", class: "job-company"
p.job-salary
| Salary:
= job.salary
.job-locations
ul
- job.cities.each do |city|
li
= city.name
.job-desc
p
= job.description
\ No newline at end of file
.search.text-center.mb-5
.overlay
.container
.row
.col-xl-9.mx-auto
h1.mb-5.mt-5
| Total:
= pluralize(Job.count, "job")
.row.justify-content-start
.col-md-10.mb-md-0.no-padding
span.fa.fa-search.form-control-feedback
= search_field_tag :search, params[:search], placeholder: "Find a job", class: "form-control rounded-left no-border-radius bg-light h-100"
.col-md-2.mb-md-0.no-padding
= button_tag "", class: "h-100 w-100 btn btn-block btn-lg btn-info fa fa-search rounded-right no-border-radius ", name: nil
| Search
\ No newline at end of file
.top_cities.mb-5
.container
h2 Top cities
.row.align-items-start.mb-3
- @top_cities.each do |city, city_jobs|
.col-4.city-item
= link_to city.name, '#', class: 'city-name'
span.job-count
| (
= pluralize(city_jobs, "job")
|)
= link_to 'See all cities', '#', class:'all-cities-btn'
\ No newline at end of file
.top_industries.mb-5
.container
h2 Top industries
.row.align-items-start
- @top_industries.each do |industry, industry_jobs|
.col-4.industry-item
= link_to industry.name, '#', class: 'industry-name'
span.job-count
| (
= pluralize(industry_jobs, "job")
|)
= link_to 'See all industries', '#', class:'all-industries-btn'
\ No newline at end of file
- provide(:title, 'Home page')
= render 'search'
= render 'latest_jobs'
= render 'top_cities'
= render 'top_industries'
# SQLite. Versions 3.8.0 and up are supported. # MySQL. Versions 5.5.8 and up are supported.
# gem install sqlite3
# #
# Ensure the SQLite 3 gem is defined in your Gemfile # Install the MySQL driver
# gem 'sqlite3' # gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
# #
default: &default default: &default
adapter: sqlite3 adapter: mysql2
encoding: utf8mb4
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000 username: root
password: 'admin'
socket: /var/run/mysqld/mysqld.sock
development: development:
<<: *default <<: *default
database: db/development.sqlite3 database: VenJob_development
# Warning: The database defined as "test" will be erased and # Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake". # re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production. # Do not set this db to the same as development or production.
test: test:
<<: *default <<: *default
database: db/test.sqlite3 database: VenJob_test
# As with config/credentials.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password or a full connection URL as an environment
# variable when you boot the app. For example:
#
# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
#
# If the connection URL is provided in the special DATABASE_URL environment
# variable, Rails will automatically merge its configuration values on top of
# the values provided in this file. Alternatively, you can specify a connection
# URL environment variable explicitly:
#
# production:
# url: <%= ENV['MY_APP_DATABASE_URL'] %>
#
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full overview on how database connection configuration can be specified.
#
production: production:
<<: *default <<: *default
database: db/production.sqlite3 database: VenJob_production
username: VenJob
password: <%= ENV['VENJOB_DATABASE_PASSWORD'] %>
...@@ -12,17 +12,17 @@ ...@@ -12,17 +12,17 @@
ActiveRecord::Schema.define(version: 2021_07_15_053121) do ActiveRecord::Schema.define(version: 2021_07_15_053121) do
create_table "active_storage_attachments", force: :cascade do |t| create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name", null: false t.string "name", null: false
t.string "record_type", null: false t.string "record_type", null: false
t.integer "record_id", null: false t.bigint "record_id", null: false
t.integer "blob_id", null: false t.bigint "blob_id", null: false
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id" t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
end end
create_table "active_storage_blobs", force: :cascade do |t| create_table "active_storage_blobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "key", null: false t.string "key", null: false
t.string "filename", null: false t.string "filename", null: false
t.string "content_type" t.string "content_type"
...@@ -34,77 +34,77 @@ ActiveRecord::Schema.define(version: 2021_07_15_053121) do ...@@ -34,77 +34,77 @@ ActiveRecord::Schema.define(version: 2021_07_15_053121) do
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
end end
create_table "active_storage_variant_records", force: :cascade do |t| create_table "active_storage_variant_records", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.integer "blob_id", null: false t.bigint "blob_id", null: false
t.string "variation_digest", null: false t.string "variation_digest", null: false
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
end end
create_table "apply_jobs", force: :cascade do |t| create_table "apply_jobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.integer "job_id", null: false t.bigint "job_id", null: false
t.integer "user_id", null: false t.bigint "user_id", null: false
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 ["job_id"], name: "index_apply_jobs_on_job_id" t.index ["job_id"], name: "index_apply_jobs_on_job_id"
t.index ["user_id"], name: "index_apply_jobs_on_user_id" t.index ["user_id"], name: "index_apply_jobs_on_user_id"
end end
create_table "cities", force: :cascade do |t| create_table "cities", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name" t.string "name"
t.integer "region" t.integer "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
end end
create_table "cities_jobs", force: :cascade do |t| create_table "cities_jobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.integer "job_id", null: false t.bigint "job_id", null: false
t.integer "city_id", null: false t.bigint "city_id", null: false
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_cities_jobs_on_city_id" t.index ["city_id"], name: "index_cities_jobs_on_city_id"
t.index ["job_id"], name: "index_cities_jobs_on_job_id" t.index ["job_id"], name: "index_cities_jobs_on_job_id"
end end
create_table "companies", force: :cascade do |t| create_table "companies", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
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
end end
create_table "favorite_jobs", force: :cascade do |t| create_table "favorite_jobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.integer "job_id", null: false t.bigint "job_id", null: false
t.integer "user_id", null: false t.bigint "user_id", null: false
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 ["job_id"], name: "index_favorite_jobs_on_job_id" t.index ["job_id"], name: "index_favorite_jobs_on_job_id"
t.index ["user_id"], name: "index_favorite_jobs_on_user_id" t.index ["user_id"], name: "index_favorite_jobs_on_user_id"
end end
create_table "history_jobs", force: :cascade do |t| create_table "history_jobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.integer "job_id", null: false t.bigint "job_id", null: false
t.integer "user_id", null: false t.bigint "user_id", null: false
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 ["job_id"], name: "index_history_jobs_on_job_id" t.index ["job_id"], name: "index_history_jobs_on_job_id"
t.index ["user_id"], name: "index_history_jobs_on_user_id" t.index ["user_id"], name: "index_history_jobs_on_user_id"
end end
create_table "industries", force: :cascade do |t| create_table "industries", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
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
end end
create_table "industries_jobs", force: :cascade do |t| create_table "industries_jobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.integer "job_id", null: false t.bigint "job_id", null: false
t.integer "industry_id", null: false t.bigint "industry_id", null: false
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_industries_jobs_on_industry_id" t.index ["industry_id"], name: "index_industries_jobs_on_industry_id"
t.index ["job_id"], name: "index_industries_jobs_on_job_id" t.index ["job_id"], name: "index_industries_jobs_on_job_id"
end end
create_table "jobs", force: :cascade do |t| create_table "jobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "title" t.string "title"
t.string "job_type" t.string "job_type"
t.string "salary" t.string "salary"
...@@ -115,13 +115,13 @@ ActiveRecord::Schema.define(version: 2021_07_15_053121) do ...@@ -115,13 +115,13 @@ ActiveRecord::Schema.define(version: 2021_07_15_053121) do
t.text "benefit" t.text "benefit"
t.text "requirement" t.text "requirement"
t.text "other_info" t.text "other_info"
t.integer "company_id", null: false t.bigint "company_id", null: false
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 "users", force: :cascade do |t| create_table "users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name" t.string "name"
t.string "email", null: false t.string "email", null: false
t.string "password_digest" t.string "password_digest"
......
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