Skip to content

Commit d93c632

Browse files
authored
Merge pull request #292 from coderdojo-japan/restful-controllers
RESTful controllers
2 parents 35a3d55 + a388d43 commit d93c632

File tree

11 files changed

+26
-36
lines changed

11 files changed

+26
-36
lines changed

app/controllers/home_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class HomeController < ApplicationController
2+
def show
3+
@dojo_count = Dojo.count
4+
@regions_and_dojos = Dojo.eager_load(:prefecture).default_order.group_by { |dojo| dojo.prefecture.region }
5+
end
6+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class LetsEncryptController < ApplicationController
2+
def show
3+
if params[:id] == ENV['LETSENCRYPT_REQUEST']
4+
render plain: ENV['LETSENCRYPT_RESPONSE']
5+
else
6+
render plain: 'Failed.'
7+
end
8+
end
9+
end

app/controllers/static_pages_controller.rb renamed to app/controllers/stats_controller.rb

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
class StaticPagesController < ApplicationController
2-
def home
3-
@dojo_count = Dojo.count
4-
@regions_and_dojos = Dojo.eager_load(:prefecture).default_order.group_by { |dojo| dojo.prefecture.region }
5-
end
6-
7-
def stats
1+
class StatsController < ApplicationController
2+
def show
83
@url = request.url
94
@dojo_count = Dojo.count
105
@regions_and_dojos = Dojo.eager_load(:prefecture).default_order.group_by { |dojo| dojo.prefecture.region }
@@ -37,12 +32,4 @@ def stats
3732
@annual_event_histories_chart = HighChartsBuilder.build_annual_event_histories
3833
@annual_participants_chart = HighChartsBuilder.build_annual_participants
3934
end
40-
41-
def letsencrypt
42-
if params[:id] == ENV['LETSENCRYPT_REQUEST']
43-
render text: ENV['LETSENCRYPT_RESPONSE']
44-
else
45-
render text: 'Failed.'
46-
end
47-
end
4835
end

app/views/static_pages/home.html.haml renamed to app/views/home/show.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
%br/
7979
%h2 全国の道場
8080
%br/
81-
= render partial: 'dojos', locals: { regions_and_dojos: @regions_and_dojos }
81+
= render partial: 'shared/dojos', locals: { regions_and_dojos: @regions_and_dojos }
8282
%section.text-center
8383
%h2.text-center
8484
%a{:href => "https://twitter.com/search?q=dojocon%20OR%20coderdojo%20OR%20%E3%82%B3%E3%83%BC%E3%83%80%E3%83%BC%E9%81%93%E5%A0%B4%20OR%20%22Coder%20Dojo%22%20OR%20%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0%E9%81%93%E5%A0%B4%20lang%3Aja"} 最近の話題

app/views/static_pages/_dojos.html+smartphone.haml renamed to app/views/shared/_dojos.html+smartphone.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
\- #{dojos.count} Dojos
1010
.panel-collapse.collapse{:id => "collapse#{index}", :role => "tabpanel"}
1111
.panel-body.grayscale-bg
12-
= render partial: 'dojo', collection: dojos
12+
= render partial: 'shared/dojo', collection: dojos

app/views/shared/_dojos.html.haml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
%ul.loaded
2+
= render partial: 'shared/dojo', collection: regions_and_dojos.values.flatten

app/views/static_pages/_dojos.html.haml

Lines changed: 0 additions & 2 deletions
This file was deleted.

app/views/static_pages/stats.html.haml renamed to app/views/stats/show.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
\- #{dojos.count} Dojos
8888
.panel-collapse.collapse{:id => "collapse#{index}", :role => "tabpanel"}
8989
.panel-body.grayscale-bg
90-
= render partial: 'dojo', collection: dojos
90+
= render partial: 'shared/dojo', collection: dojos
9191

9292
%h3 関連リンク
9393
%ul{:style => "list-style: none; margin-left: -40px;"}

config/routes.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
# For details on the DSL available within this file,
33
# see http://guides.rubyonrails.org/routing.html
44

5+
root "home#show"
6+
57
# Render legal documents by using Keiyaku CSS
68
# https://github.com/cognitom/keiyaku-css
79
get "/docs/code_of_conduct", to: redirect('/docs/code-of-conduct')
810
resources :docs, only: [:index, :show]
911

10-
# Static Pages
11-
root "static_pages#home"
12-
get "/stats", to: 'static_pages#stats'
12+
resource :stats, only: %i(show)
1313

1414
# Redirects
1515
get "/releases/2016/12/12/new-backend", to: redirect('/news/2016/12/12/new-backend')
1616
get "/blogs/2016/12/12/new-backend", to: redirect('/news/2016/12/12/new-backend')
1717

1818
# Issue SSL Certification
19-
get "/.well-known/acme-challenge/:id" => "static_pages#letsencrypt"
19+
get "/.well-known/acme-challenge/:id" => "lets_encrypt#show"
2020

2121
# Sessions
2222
get '/logout', to: 'sessions#destroy'

spec/controllers/static_pages_controller_spec.rb

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)