Skip to content

Commit 88937e7

Browse files
committed
improve: 対象期間セレクトボックスの変更で自動遷移(表示ボタン削除)
- onchangeイベントで選択と同時にページ遷移 - 「表示」ボタンを削除してUIをシンプルに - form_withタグも不要になったため削除 - より直感的で素早い操作が可能に
1 parent fde0c73 commit 88937e7

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

app/views/dojos/index.html.erb

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,23 @@
3737
</div>
3838
<% end %>
3939

40-
<%= form_with(url: dojos_path, method: :get, local: true, style: 'margin-top: 15px;') do |f| %>
41-
<div style="display: flex; align-items: center; justify-content: center; gap: 10px;">
42-
<%= label_tag :year, '対象期間:', style: 'font-weight: bold;' %>
43-
<%= select_tag :year,
44-
options_for_select(
45-
(2012..Date.current.year).to_a.reverse.map { |y| [y.to_s + '年', y] },
46-
params[:year]
47-
),
48-
include_blank: '全期間',
49-
style: 'padding: 5px; border: 1px solid #ced4da; border-radius: 4px;' %>
50-
51-
<%= button_tag type: 'submit', style: 'padding: 5px 15px; background: #17a2b8; color: white; border: none; border-radius: 4px; cursor: pointer;' do %>
52-
表示
53-
<% end %>
54-
55-
<%= link_to 'CSV', dojos_path(format: :csv, year: params[:year]),
56-
style: 'padding: 5px 15px; background: #28a745; color: white; text-decoration: none; border-radius: 4px;' %>
57-
58-
<%= link_to 'JSON', dojos_path(format: :json, year: params[:year]),
59-
style: 'padding: 5px 15px; background: #6c757d; color: white; text-decoration: none; border-radius: 4px;' %>
60-
</div>
61-
<% end %>
40+
<div style="display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 15px;">
41+
<%= label_tag :year, '対象期間:', style: 'font-weight: bold;' %>
42+
<%= select_tag :year,
43+
options_for_select(
44+
(2012..Date.current.year).to_a.reverse.map { |y| [y.to_s + '年', y] },
45+
params[:year]
46+
),
47+
include_blank: '全期間',
48+
onchange: "window.location.href = '#{dojos_path}?year=' + this.value",
49+
style: 'padding: 5px; border: 1px solid #ced4da; border-radius: 4px; cursor: pointer;' %>
50+
51+
<%= link_to 'CSV', dojos_path(format: :csv, year: params[:year]),
52+
style: 'padding: 5px 15px; background: #28a745; color: white; text-decoration: none; border-radius: 4px;' %>
53+
54+
<%= link_to 'JSON', dojos_path(format: :json, year: params[:year]),
55+
style: 'padding: 5px 15px; background: #6c757d; color: white; text-decoration: none; border-radius: 4px;' %>
56+
</div>
6257

6358
<p style="font-size: smaller; color: #6c757d; margin-top: 15px;">
6459
対象期間を選択すると、その時点のアクティブな道場の一覧を表示・ダウンロードできます。

spec/requests/dojos_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,11 @@
240240
end
241241

242242
describe "HTML format year selection UI" do
243-
it "shows year selection form" do
243+
it "shows year selection form with auto-submit" do
244244
get dojos_path
245245
expect(response.body).to include('対象期間')
246246
expect(response.body).to include('<select')
247+
expect(response.body).to include('onchange')
247248
expect(response.body).to include('2012')
248249
expect(response.body).to include(Date.current.year.to_s)
249250
end

0 commit comments

Comments
 (0)