Commit 831d463f by Tô Ngọc Ánh

Fix slug

parent 84915250
Pipeline #826 failed with stages
in 0 seconds
...@@ -8,11 +8,11 @@ class Industry < ApplicationRecord ...@@ -8,11 +8,11 @@ class Industry < ApplicationRecord
has_and_belongs_to_many :jobs has_and_belongs_to_many :jobs
before_save :add_slug before_save :add_slug, unless: :slug
private private
def add_slug def add_slug
self.slug = "#{self.id}-#{self.to_slug(self.name)}" self.slug = "#{self.to_slug(self.name)}-#{Time.now.to_i}#{rand(10000)}"
end end
end end
class Job < ApplicationRecord class Job < ApplicationRecord
NUMBER_LATEST_JOB = 6 NUMBER_LATEST_JOB = 6
WORDS_SHORT_DESCRIPTION = 250
belongs_to :company belongs_to :company
has_many :applied_jobs has_many :applied_jobs
......
...@@ -13,11 +13,11 @@ class Location < ApplicationRecord ...@@ -13,11 +13,11 @@ class Location < ApplicationRecord
has_many :locations_jobs has_many :locations_jobs
has_many :jobs, through: :locations_jobs has_many :jobs, through: :locations_jobs
before_save :add_slug before_save :add_slug, unless: :slug
private private
def add_slug def add_slug
self.slug = "#{self.id}-#{self.to_slug(self.city)}" self.slug = "#{self.to_slug(self.city)}-#{Time.now.to_i}#{rand(10000)}"
end end
end end
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<% end %> <% end %>
</p> </p>
<p><strong>Salary: </strong><%= job.salary %></p> <p><strong>Salary: </strong><%= job.salary %></p>
<p class='card-text'><%= strip_tags(job.description).truncate(250) %></p> <p class='card-text'><%= strip_tags(job.description).truncate(Job::WORDS_SHORT_DESCRIPTION) %></p>
</div> </div>
<div class='btn-favorite p-2'> <div class='btn-favorite p-2'>
<%= link_to 'Favorite', '#', class: 'btn btn-outline-danger btn-lg' %> <%= link_to 'Favorite', '#', class: 'btn btn-outline-danger btn-lg' %>
......
...@@ -2,14 +2,14 @@ namespace :create_slug do ...@@ -2,14 +2,14 @@ namespace :create_slug do
desc 'Create slug model Location' desc 'Create slug model Location'
task locations: :environment do task locations: :environment do
Location.all.each do |location| Location.all.each do |location|
location.update_attributes(slug: "") location.update_attributes(slug: "#{location.to_slug(location.city)}-#{Time.now.to_i}#{rand(10000)}")
end end
end end
desc 'Create slug model Industry' desc 'Create slug model Industry'
task industries: :environment do task industries: :environment do
Industry.all.each do |industry| Industry.all.each do |industry|
industry.update_attributes(slug: "") industry.update_attributes(slug: "#{industry.to_slug(industry.name)}-#{Time.now.to_i}#{rand(10000)}")
end end
end end
......
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