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 @@
class JobsController < ApplicationController
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_ids = job_found[:job_id]
@job_num = job_found[:num]
......@@ -19,14 +19,17 @@ class JobsController < ApplicationController
@cities = City.all.select { |city| city.jobs.any? }
end
def jobs_in_city
@city = City.find_by(slug: params[:slug])
@jobs = @city.jobs.page(params[:page])
end
def home
@jobs = Job.all.order(updated_at: :desc).take(5)
@cities = City.all.select { |city| city.jobs.any? }.take(9)
@industries = Industry.all.select { |industry| industry.jobs.any? }.take(9)
end
private
def search_filter
params.permit(:search)
s = params[:search].blank? ? '*' : params[:search]
s.gsub(/[\/]/,'*')
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 @@
<%= city.name %>
<%= link_to pluralize(city.jobs.count, 'job'),
controller: 'jobs',
action: 'jobs_in_city',
slug: city.slug %>
action: 'index',
search: city.name %>
</div>
<% end %>
</div>
......@@ -47,8 +47,8 @@
<%= industry.name %>
<%= link_to pluralize(industry.jobs.count, 'job'),
controller: 'jobs',
action: 'jobs_in_city',
slug: industry.slug %>
action: 'index',
search: industry.name %>
</div>
<% end %>
</div>
......
......@@ -2,7 +2,6 @@
<aside class="col-md-16">
<section class="user_info">
<h4>
<%= @job.title %>
</h4>
......@@ -14,7 +13,7 @@
<table class="table table-hover">
<tbody>
<tr>
<th scope="row col-8">Job title</th>
<th scope="row">Job title</th>
<td><%= @job.title %></td>
</tr>
<tr>
......@@ -23,17 +22,17 @@
</tr>
<tr>
<th scope="row">Location</th>
<td colspan="2">
<td>
<%= @job.cities.map(&:name).reject(&:blank?).join(', ') %>
</td>
</tr>
<tr>
<th scope="row">Salary</th>
<td colspan="2"><%= @job.salary %></td>
<td><%= @job.salary %></td>
</tr>
<tr>
<th scope="row">Description</th>
<td colspan="2"><%= @job.description %></td>
<td><%= @job.description %></td>
</tr>
</tbody>
</table>
......
<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
root to: 'jobs#home'
resources :entries, only: [:new, :create, :show, :edit, :update]
resources :cities, only: :index
resources :industries, only: :index
get '/apply', to: 'entries#new'
resources :jobs do
collection do
get 'home'
get 'city'
get 'city/:slug', to: 'jobs#jobs_in_city'
get 'city/:search', to: 'jobs#index'
get 'industry/:search', to: 'jobs#index'
get 'search'
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