Skip to content

Commit 5cda416

Browse files
committed
feat: エラーメッセージを年次フィルタリングセクションに表示
- flash[:alert]を同じ位置に赤い背景色で表示 - 内部リンク(#table)でジャンプしても見える位置に配置 - リダイレクト時も#tableアンカーを追加 - Bootstrap風のアラートスタイル(background: #f8d7da)を適用
1 parent 27928f4 commit 5cda416

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

app/controllers/dojos_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def index
99
# 有効な年の範囲をチェック
1010
unless year.between?(2012, Date.current.year)
1111
flash[:alert] = "指定された年(#{year})は無効です。2012年から#{Date.current.year}年の間で指定してください。"
12-
return redirect_to dojos_path
12+
return redirect_to dojos_path(anchor: 'table')
1313
end
1414

1515
@selected_year = year
@@ -20,7 +20,7 @@ def index
2020
@page_title = "#{@selected_year}年末時点のCoderDojo一覧"
2121
rescue ArgumentError
2222
flash[:alert] = "無効な年が指定されました"
23-
return redirect_to dojos_path
23+
return redirect_to dojos_path(anchor: 'table')
2424
end
2525
else
2626
# yearパラメータなしの場合(既存の実装そのまま)

app/views/dojos/index.html.erb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@
3333
年次データのフィルタリング
3434
</h3>
3535

36-
<% if @selected_year %>
36+
<% if flash[:alert] %>
37+
<div style="padding: 10px; background: #f8d7da; border: 1px solid #f5c6cb; border-radius: 4px; margin-bottom: 15px; color: #721c24;">
38+
<%= flash[:alert] %>
39+
</div>
40+
<% elsif @selected_year %>
3741
<div style="padding: 10px; background: #d1ecf1; border: 1px solid #bee5eb; border-radius: 4px; margin-bottom: 15px;">
3842
<strong><%= @selected_year %>年末時点</strong>のアクティブな道場を表示中
3943
</div>

spec/requests/dojos_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,20 @@
5454

5555
it "rejects years before 2012" do
5656
get dojos_path(year: 2011, format: :json)
57-
expect(response).to redirect_to(dojos_path)
57+
expect(response).to redirect_to(dojos_path(anchor: 'table'))
5858
expect(flash[:alert]).to include("2012年から")
5959
end
6060

6161
it "rejects years after current year" do
6262
future_year = Date.current.year + 1
6363
get dojos_path(year: future_year, format: :json)
64-
expect(response).to redirect_to(dojos_path)
64+
expect(response).to redirect_to(dojos_path(anchor: 'table'))
6565
expect(flash[:alert]).to include("無効です")
6666
end
6767

6868
it "handles invalid year strings" do
6969
get dojos_path(year: "invalid", format: :json)
70-
expect(response).to redirect_to(dojos_path)
70+
expect(response).to redirect_to(dojos_path(anchor: 'table'))
7171
expect(flash[:alert]).to include("無効")
7272
end
7373
end

0 commit comments

Comments
 (0)