Commit dee1e937 by Thanh Hung Pham

Create cities and categories list page

parent 0b509ba1
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
// Place all the styles related to the Categories controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the Cities controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class CategoriesController < ApplicationController
def show
@categories = Category.all
end
end
class CitiesController < ApplicationController
def show
@areas = Area.all
end
end
module CategoriesHelper
end
module CitiesHelper
def get_city_by_area(area)
City.where(area: area)
end
end
<%- provide('title', 'Industries') -%>
<div class="center jumbotron">
<div class="well">
<p> Industry list </p>
<div class="list_categories">
<div class="row">
<%- @categories.each do |category| -%>
<%- if category.job_category.count > 0 -%>
<div class="col-md-3">
<%= category.name %>
(<%= pluralize(category.job_category.count, 'job') %>)
</div>
<%- end -%>
<%- end -%>
</div>
</div>
</div>
</div>
<%- provide(:title, 'Cities') -%>
<div class="center jumbotron">
<div class="well">
<p> City list </p>
<div class="list_areas">
<div class="row">
<%- @areas.each do |area| -%>
<div class="col-md-6">
<%= area.name %>
</div>
<%- end -%>
</div>
</div>
</div>
<%- @areas.each do |area| -%>
<div class="well">
<p> <%= area.name %> </p>
<div class="row">
<%- get_city_by_area(area).each do |city| -%>
<%- if city.job.count > 0 -%>
<div class="col-md-4">
<%= city.name %>
(<%= pluralize(city.job.count, 'job') %>)
</div>
<%- end -%>
<%- end -%>
</div>
</div>
<%- end -%>
</div>
......@@ -33,7 +33,7 @@
</div>
</div>
<div class="well">
<p> Top cities </p><%= link_to 'All cities', '#' %>
<p> Top cities <%= link_to 'All cities', cities_path %> </p>
<div class="top_cities">
<div class="row">
<%- @top_cities.limit(9).each do |city| -%>
......@@ -46,7 +46,7 @@
</div>
</div>
<div class="well">
<p> Top industries </p><%= link_to 'All industries', '#' -%>
<p> Top industries <%= link_to 'All industries', categories_path -%> </p>
<div class="top_industries">
<div class="row">
<%- @top_categories.limit(9).each do |category| -%>
......
Rails.application.routes.draw do
root 'static_pages#home'
get 'static_pages/home'
get '/register', to: 'users#new'
get '/cities', to: 'cities#show'
get '/categories', to: 'categories#show'
resource :users
resource :cities
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
require 'test_helper'
class CategoriesControllerTest < ActionDispatch::IntegrationTest
test "should get show" do
get categories_show_url
assert_response :success
end
end
require 'test_helper'
class CitiesControllerTest < ActionDispatch::IntegrationTest
test "should get show" do
get cities_show_url
assert_response :success
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