Commit 8afb0695 by Quang Vinh Nguyen

Add industries controller

parent 7f7df78b
class CitiesController < ApplicationController
def index
@cities = City.all.select { |city| city.jobs.any? }
end
end
class IndustriesController < ApplicationController
def index
@industries = Industry.all.select { |industry| industry.jobs.any? }
end
end
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
class JobsController < ApplicationController class JobsController < ApplicationController
def index def index
search_str = params[:search].blank? ? '*' : params[:search] search_str = search_filter
job_found = Job.search(kw: search_str, page: params[:page].to_i) job_found = Job.search(kw: search_str, page: params[:page].to_i)
job_ids = job_found[:job_id] job_ids = job_found[:job_id]
@job_num = job_found[:num] @job_num = job_found[:num]
...@@ -19,14 +19,17 @@ class JobsController < ApplicationController ...@@ -19,14 +19,17 @@ class JobsController < ApplicationController
@cities = City.all.select { |city| city.jobs.any? } @cities = City.all.select { |city| city.jobs.any? }
end end
def jobs_in_city
@city = City.find_by(slug: params[:slug])
@jobs = @city.jobs.page(params[:page])
end
def home def home
@jobs = Job.all.order(updated_at: :desc).take(5) @jobs = Job.all.order(updated_at: :desc).take(5)
@cities = City.all.select { |city| city.jobs.any? }.take(9) @cities = City.all.select { |city| city.jobs.any? }.take(9)
@industries = Industry.all.select { |industry| industry.jobs.any? }.take(9) @industries = Industry.all.select { |industry| industry.jobs.any? }.take(9)
end end
private
def search_filter
params.permit(:search)
s = params[:search].blank? ? '*' : params[:search]
s.gsub(/[\/]/,'*')
end
end end
module CitiesHelper
end
module IndustriesHelper
end
<h3>Location</h3>
<div class="container">
<div class="row">
<% @cities.each do |city| %>
<div class="col-6 col-md-4 list-group-item">
<%= city.name %>
<%= link_to pluralize(city.jobs.count, 'job'),
controller: 'jobs',
action: 'index',
search: "#{city.name}" %>
</div>
<% end %>
</div>
</div><br>
<h1>Industries</h1>
<div class="container">
<div class="row">
<% @industries.each do |industry| %>
<div class="col-6 col-md-4 list-group-item">
<%= industry.name %>
<%= link_to pluralize(industry.jobs.count, 'job'),
controller: 'jobs',
action: 'index',
search: "#{industry.slug}" %>
</div>
<% end %>
</div>
</div><br>
<h3>Show all <%= pluralize(@cities.count, 'city') %></h3>
<ul class='list-group'>
<% @cities.each do |city| %>
<li class = 'list-group-item'>
<%= city.name %>
<%= link_to pluralize(city.jobs.count, 'job'),
controller: 'jobs',
action: 'jobs_in_city',
slug: city.slug %>
</li>
<% end %>
</ul>
\ No newline at end of file
...@@ -32,8 +32,8 @@ ...@@ -32,8 +32,8 @@
<%= city.name %> <%= city.name %>
<%= link_to pluralize(city.jobs.count, 'job'), <%= link_to pluralize(city.jobs.count, 'job'),
controller: 'jobs', controller: 'jobs',
action: 'jobs_in_city', action: 'index',
slug: city.slug %> search: city.name %>
</div> </div>
<% end %> <% end %>
</div> </div>
...@@ -47,8 +47,8 @@ ...@@ -47,8 +47,8 @@
<%= industry.name %> <%= industry.name %>
<%= link_to pluralize(industry.jobs.count, 'job'), <%= link_to pluralize(industry.jobs.count, 'job'),
controller: 'jobs', controller: 'jobs',
action: 'jobs_in_city', action: 'index',
slug: industry.slug %> search: industry.name %>
</div> </div>
<% end %> <% end %>
</div> </div>
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
<aside class="col-md-16"> <aside class="col-md-16">
<section class="user_info"> <section class="user_info">
<h4> <h4>
<%= @job.title %> <%= @job.title %>
</h4> </h4>
...@@ -14,7 +13,7 @@ ...@@ -14,7 +13,7 @@
<table class="table table-hover"> <table class="table table-hover">
<tbody> <tbody>
<tr> <tr>
<th scope="row col-8">Job title</th> <th scope="row">Job title</th>
<td><%= @job.title %></td> <td><%= @job.title %></td>
</tr> </tr>
<tr> <tr>
...@@ -23,21 +22,21 @@ ...@@ -23,21 +22,21 @@
</tr> </tr>
<tr> <tr>
<th scope="row">Location</th> <th scope="row">Location</th>
<td colspan="2"> <td>
<%= @job.cities.map(&:name).reject(&:blank?).join(', ') %> <%= @job.cities.map(&:name).reject(&:blank?).join(', ') %>
</td> </td>
</tr> </tr>
<tr> <tr>
<th scope="row">Salary</th> <th scope="row">Salary</th>
<td colspan="2"><%= @job.salary %></td> <td><%= @job.salary %></td>
</tr> </tr>
<tr> <tr>
<th scope="row">Description</th> <th scope="row">Description</th>
<td colspan="2"><%= @job.description %></td> <td><%= @job.description %></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<%= link_to "Apply", apply_path(job_id: @job.id), <%= link_to "Apply", apply_path(job_id: @job.id),
class: "btn btn-secondary" %> class: "btn btn-secondary" %>
<%= link_to 'Back', :back, class: "btn btn-secondary" %> <%= link_to 'Back', :back, class: "btn btn-secondary" %>
......
<div class='container'>
<div class='jobs-list'>
<ul>
<% @jobs.each do |job| %>
<li>
<div class="card">
<h5 class="card-header"><%= job.title %></h5>
<div class="card-body">
<h5 class="card-title"><%= job.company.name %></h5>
<p class="card-text"><% job.description %></p>
<%= link_to 'Show job', job, class: 'card-link' %>
</div>
</div>
</li>
<% end %>
</ul>
</div>
<h4> Cities list </h4>
<div class='cities-list'>
<ul>
<% @cities.each do |city| %>
<li>
<%= city.code %> -- <%= city.name %>
<%= link_to 'Show', controller: 'jobs', action: 'jobs_in_city', slug: city.slug %>
</li>
<% end %>
</ul>
</div
</div>
Rails.application.routes.draw do Rails.application.routes.draw do
root to: 'jobs#home' root to: 'jobs#home'
resources :entries, only: [:new, :create, :show, :edit, :update] resources :entries, only: [:new, :create, :show, :edit, :update]
resources :cities, only: :index
resources :industries, only: :index
get '/apply', to: 'entries#new' get '/apply', to: 'entries#new'
resources :jobs do resources :jobs do
collection do collection do
get 'home' get 'home'
get 'city' get 'city/:search', to: 'jobs#index'
get 'city/:slug', to: 'jobs#jobs_in_city' get 'industry/:search', to: 'jobs#index'
get 'search' get 'search'
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