Skip to content

Commit 5e9a240

Browse files
committed
Display provider num for region, disable changing file prefix #444
1 parent 0ab0989 commit 5e9a240

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

app/controllers/regions_controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ class RegionsController < ApplicationController
44

55
# GET /regions
66
def index
7-
@regions = Region.all
7+
@regions = Region
8+
.left_joins(:providers)
9+
.select("regions.*, COUNT(providers.id) AS providers_count")
10+
.group("regions.id")
11+
.order(:name)
812
end
913

1014
# GET /regions/1

app/views/providers/_form.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
</div>
2626
</div>
2727

28-
<div class="col-md-4">
28+
<!--div class="col-md-4">
2929
<div class="form-group">
3030
<%= form.label :file_name_prefix, style: "display: block" %>
3131
<%= form.text_field :file_name_prefix, id: "basicInput", class: "form-control" %>
3232
</div>
33-
</div>
33+
</div-->
3434

3535
<div class="col-md-4">
3636
<div class="form-group">

app/views/regions/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<% @regions.each do |region| %>
2727
<tr>
2828
<td class="text-bold-500"><%= region.name %></td>
29-
<td>1</td>
29+
<td><%= region.providers_count %></td>
3030
<td class="text-end">
3131
<%= link_to region, class: "btn btn-primary btn-sm" do %>
3232
<i class="bi bi-search"></i> View

spec/views/regions/index.html.erb_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
require "rails_helper"
22

33
RSpec.describe "regions/index", type: :view do
4+
let!(:regions) { [ create(:region, name: "Region 1"), create(:region, name: "Region 2") ] }
45
before(:each) do
5-
assign(:regions, [ create(:region, name: "Region 1"), create(:region, name: "Region 2") ])
6+
assign :regions, Region
7+
.left_joins(:providers)
8+
.select("regions.*, COUNT(providers.id) AS providers_count")
9+
.group("regions.id")
10+
.order(:name)
611
end
712

813
it "renders a list of regions" do

0 commit comments

Comments
 (0)