Skip to content

Commit f48e7eb

Browse files
committed
Add internal Dojo API to make news easier
下記お知らせ記事の「寄贈先の CoderDojo 一覧」を簡単に作りたい。 与えられた Dojo 名と一致した Dojo のリンク付きテキストを返し、 今後同様のセクションを作るときは本 API で Dojo 一覧のリストを用意する。 「CoderDojo 一覧」が用意されているお知らせ記事の例 https://news.coderdojo.jp/2022/05/16/1500-microbits-to-coderdojo/
1 parent 53a9c55 commit f48e7eb

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

app/controllers/dojos_controller.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class DojosController < ApplicationController
2+
def index
3+
@dojo_data = []
4+
Dojo.active.each do |dojo|
5+
@dojo_data << {
6+
name: dojo.name,
7+
url: dojo.url,
8+
prefecture: dojo.prefecture.region,
9+
linked_text: "<a href='#{dojo.url}'>'#{dojo.name}</a>(#{dojo.prefecture.region})",
10+
}
11+
end
12+
13+
respond_to do |format|
14+
format.json { render json: @dojo_data }
15+
16+
# No corresponding View for now.
17+
# Only for API: GET /dojos.json
18+
format.html { redirect_to root_url(anchor: 'dojos') }
19+
end
20+
end
21+
end

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
get "/kata" => "docs#kata"
5252
#get "/debug/kata" => "docs#kata"
5353

54-
54+
resources :dojos, only: %i(index) # Only API: GET /dojos.json
5555
resources :docs, only: %i(index show)
5656
resources :podcasts, only: %i(index show)
5757
resources :spaces, only: %i(index)

0 commit comments

Comments
 (0)