change find id to slug

parent 30c1a60e
Pipeline #1383 canceled with stages
in 0 seconds
......@@ -58,7 +58,7 @@
}
}
.apply-job btn{
.apply-job .btn {
align-items: center;
justify-content: center;
}
......
......@@ -14,6 +14,6 @@ class JobsController < ApplicationController
end
def show
@job = Job.latest_jobs.find_by(id: params[:job_id])
@job = Job.latest_jobs.find_by(slug: params[:job_slug])
end
end
\ No newline at end of file
module ApplicationHelper
def format_datetime(input)
input.strftime('%d/%m/%Y')
end
end
class Job < ApplicationRecord
extend FriendlyId
friendly_id :title, use: %i[slugged finders]
belongs_to :company
has_many :apply_jobs, dependent: :destroy
has_many :favorite_jobs, dependent: :destroy
......@@ -7,4 +9,8 @@ class Job < ApplicationRecord
has_and_belongs_to_many :cities
LATEST_JOB_NUMBER = 5
scope :latest_jobs, -> { includes(:cities, :industries, :company).order('created_at DESC') }
def normalize_friendly_id(string)
string.to_s.to_slug.normalize(transliterations: :vietnamese).to_s
end
end
\ No newline at end of file
......@@ -2,10 +2,10 @@ nav.breadcrumb[style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb"]
ol.breadcrumb.py-3
li.breadcrumb-item
= link_to "Top", root_path
li.breadcrumb-item
li.breadcrumb-item
- @job.cities.each do |city|
= link_to city.name, city_slug_path(city.slug)
li.breadcrumb-item
li.breadcrumb-item
- @job.industries.each do |industry|
= link_to industry.name, industry_slug_path(industry.slug)
li.breadcrumb-item.active = link_to @job.title
\ No newline at end of file
......@@ -15,9 +15,9 @@
.row.bg-white
.col-10.p-3.border.card-body.text-dark
h5.mb-1
= link_to job.title, detail_path(job.id)
= link_to job.title, detail_path(job.slug)
p.mb-1
= link_to job.company.name, "#"
= job.company.name
p.mb-1
i.fas.fa-dollar-sign.m-1
| Lương:
......
......@@ -6,7 +6,7 @@
h1.mb-2
= @job.title
h3.mb-2
= link_to @job.company.name, "#"
= @job.company.name
.row
.col
p.mb-2
......@@ -28,7 +28,7 @@
= @job.experience
p.mb-2
| Expired at:
= @job.expired_at.strftime("%d/%m/%Y")
= format_datetime(@job.expired_at)
h5.my-3
| Benefits
p.mb-2
......
......@@ -11,9 +11,9 @@ h3.p-2
.card.my-3
.card-body.text-dark
h5.mb-1
= link_to job.title, detail_path(job.id)
= link_to job.title, detail_path(job.slug)
p.mb-1
= link_to job.company.name, "#"
= job.company.name
p.mb-1
i.fas.fa-dollar-sign.m-1
| Lương:
......
......@@ -4,5 +4,5 @@ Rails.application.routes.draw do
get 'industries', to: 'industries#show'
get 'jobs/city/:city_slug', to: 'jobs#index', as: 'city_slug'
get 'jobs/industry/:industry_slug', to: 'jobs#index', as: 'industry_slug'
get 'detail/:job_id', to: 'jobs#show', as: 'detail'
get 'detail/:job_slug', to: 'jobs#show', as: 'detail'
end
\ No newline at end of file
class AddSlugToJobs < ActiveRecord::Migration[6.1]
def change
add_column :jobs, :slug, :string
add_index :jobs, :slug, unique: true
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_07_31_111344) do
ActiveRecord::Schema.define(version: 2021_08_05_021856) do
create_table "apply_jobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.bigint "user_id", null: false
......@@ -119,7 +119,9 @@ ActiveRecord::Schema.define(version: 2021_07_31_111344) do
t.datetime "expired_at"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "slug"
t.index ["company_id"], name: "index_jobs_on_company_id"
t.index ["slug"], name: "index_jobs_on_slug", unique: true
end
create_table "regions", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
......
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