City list
-
1 require 'test_helper' -
-
added 12 commits
-
009e0198...b36f3848 - 11 commits from branch
master - 167fb2c0 - Merged master
Toggle commit list -
009e0198...b36f3848 - 11 commits from branch
-
-
-
3 3 has_many :jobs 4 4 validates_presence_of :industry_name 5 5 scope :top_industry_by_job, ->{joins(:jobs).select('industries.*, COUNT(jobs.id) as job_count').group('jobs.industry_id').order(:job_count).last(9)} 6 scope :all_industry_by_job, ->{joins(:jobs).select('industries.*, COUNT(jobs.id) as job_count').group('jobs.industry_id').order(:job_count).reverse_order} -
app/views/cities/index.html.erb 0 → 100644
2 <div id="search" class="container p-5 my-2 bg-secondary text-white"> 3 <%= form_tag job_search_path, method: :get do %> 4 <p> 5 <%= text_field_tag :search, params[:search] %> 6 <%= button_tag "Search", name: nil %> 7 </p> 8 <% end %> 9 </div> 10 11 <div id="city_list"class="container p-5 my-2 bg-secondary text-white"> 12 <font color="red"><b><label > City List:</label></b></font> 13 <br> 14 <label><a href="#topcity_vn">Viet Nam</a></label> 15 <br> 16 <label><a href="#topcity_nn">International</a></label> 17 -
app/views/cities/index.html.erb 0 → 100644
9 </div> 10 11 <div id="city_list"class="container p-5 my-2 bg-secondary text-white"> 12 <font color="red"><b><label > City List:</label></b></font> 13 <br> 14 <label><a href="#topcity_vn">Viet Nam</a></label> 15 <br> 16 <label><a href="#topcity_nn">International</a></label> 17 18 19 20 </div> 21 22 <div id="topcity_vn" class="container p-5 my-2 bg-secondary text-white"> 23 <font color="red"><b><label > Viet Nam:</label></b></font> 24 <% @all_cities_vn.each do |city_vn| %> -
Edited by Hiếu Lê
Naming convention
Có 1 lỗi chung đang sai nhiều chỗ đó là cách đặt tên biến. Nếu dữ liệu trả về array, hash,...nói chung là số nhiều thì biến phải là số nhiều để đọc tên biến là biết nó chứa cái gì luôn. VD:
@top_cities_vn = City.top_city_by_job @top_cities_nn = City.top_city_by_job_nn @all_cities_vn = City.all_city_by_job @all_cities_nn = City.all_city_by_job_nnNên đặt là:
@top_cities_vn = City.top_cities_by_job @top_cities_nn = City.top_cities_by_job_nn @all_cities_vn = City.all_cities_by_job @all_cities_nn = City.all_cities_by_job_nn@all_industry = Industry.all_industry_by_jobNên là
@all_industries = Industry.all_industries_by_job -
Edited by Hiếu Lê
Cách đặt tên field trong từng table.
Trong bảng
companiescó các fieldcompany_name,company_description. Tên khá dài dòng lúc gọi ra cũng dài luôn.Ví dụ:
company.company_name-> Chữ company gọi 2 lần.Thực ra tên field chỉ cần là
name,descriptionlà đủ.Ví dụ:
company.name-> Ai cũng hiểu là lấynamecủacompanyTương tự cho các table khác cũng bị tương tự.
-
-
app/assets/stylesheets/cities.scss 0 → 100644
1 // Place all the styles related to the cities controller here. -
app/assets/stylesheets/cities.scss 0 → 100644
1 // Place all the styles related to the cities controller here. 2 // They will automatically be included in application.css. -
app/assets/stylesheets/industries.scss 0 → 100644
1 // Place all the styles related to the industries controller here. -
2 2 belongs_to :area 3 3 has_many :jobs 4 4 validates_presence_of :city_name 5 scope :top_city_by_job, ->{joins(:jobs).select('cities.*, COUNT(jobs.id) as job_count').group('jobs.city_id').order(:job_count).last(9)} 5 6 def self.top_cities_by_job 7 City.joins(:jobs).select('cities.*, COUNT(jobs.id) as job_count').group('jobs.city_id').order(:job_count).reverse_order.first(9) -
MasterEdited by Ba Toi Dang
City.joins(:jobs).select('cities.*, COUNT(jobs.id) as job_count').group('jobs.city_id').order(:job_count).reverse_order.first(9)=>
joins(:jobs).select('cities.*, COUNT(jobs.id) as job_count').group('jobs.city_id').order(:job_count).reverse_order.first(9)Làm vậy để giữ chain query của active_record. Anh check các chỗ khác nha.
-
-
-
2 2 has_many :industry_jobs 3 3 has_many :jobs 4 4 validates_presence_of :industry_name 5 scope :top_industry_by_job, ->{joins(:jobs).select('industries.*, COUNT(jobs.id) as job_count').group('jobs.industry_id').order(:job_count).last(9)} 5 6 def self.top_industries_by_job 7 Industry.joins(:jobs).select('industries.*, COUNT(jobs.id) as job_count').group('jobs.industry_id').order(:job_count).last(9) -
MasterEdited by Ba Toi Dang
@thanhnd không sử dụng magic number
9di chuyển các biến số thành 1 constant. Anh kiểm tra những chỗ khác nha.http://zigexn-ventura.github.io/magic-number-and-handling-in-rails/
-
-
-
-
-
closed
Toggle commit list -
reopened
Toggle commit list -
canceled the automatic merge
Toggle commit list -
canceled the automatic merge
Toggle commit list -
merged
Toggle commit list