Skip to content

給付金コースのプラクティスの質問一覧に元コースのプラクティスの質問も表示できるようにした#9975

Open
djkazunoko wants to merge 13 commits into
mainfrom
feature/show-source-practice-qas-in-grant-course-practice
Open

給付金コースのプラクティスの質問一覧に元コースのプラクティスの質問も表示できるようにした#9975
djkazunoko wants to merge 13 commits into
mainfrom
feature/show-source-practice-qas-in-grant-course-practice

Conversation

@djkazunoko

@djkazunoko djkazunoko commented May 4, 2026

Copy link
Copy Markdown
Contributor

Issue

概要

  • 給付金コースのプラクティスの質問一覧に質問の表示範囲を切り替えるタブを追加しました。
    • 「元コース + 給付金コース」と「給付金コース」を切り替える。
    • このタブは給付金コースのプラクティスの質問一覧画面でのみ表示されます。
  • 質問タブの件数表示を質問の表示範囲に応じて変更するようにしました。
    • 「全て」では元コースを含む合算件数を表示
    • 「給付金コース」では給付金コースのみの件数を表示
    • 質問ページ以外では合算件数を表示

※ 給付金コース = Railsエンジニア(Reスキル講座認定)コース(https://bootcamp.fjord.jp/courses/47/practices)

変更確認方法

  1. feature/show-source-practice-qas-in-grant-course-practiceをローカルに取り込む
  2. bin/rails db:seed:replantを実行
  3. bin/devでサーバーを起動
  4. localhost:3000にアクセスし、grant-courseでログイン

質問表示切り替えタブの表示・非表示の確認

  1. /practices/200789251/questions(給付金コースのプラクティスの質問一覧)にアクセスし、質問表示切り替えタブが表示されていることを確認する
  2. /practices/473419339/questions(給付金コース以外のプラクティスの質問一覧)にアクセスし、質問表示切り替えタブが表示されていないことを確認する

質問の表示・非表示の確認

質問A → 給付金コースのプラクティスの質問
質問B → 給付金コースのプラクティスの質問(解決済み)
質問C → 給付金コースのコピー元プラクティスの質問
質問D → 給付金コースのコピー元プラクティスの質問(解決済み)

  1. /practices/200789251/questions(給付金コースのプラクティスの質問一覧)にアクセス
  2. 解決・未解決フィルターが「全ての質問」、質問表示切り替えタブが「全て」であることを確認して、全ての質問が表示されていることを確認する
  3. 解決・未解決フィルターが「解決済み」、質問表示切り替えタブが「全て」を選択して、質問B・Dのみ表示されていることを確認する
  4. 解決・未解決フィルターが「未解決」、質問表示切り替えタブが「全て」を選択して、質問A・Cのみ表示されていることを確認する
  5. 解決・未解決フィルターが「全ての質問」、質問表示切り替えタブが「給付金コース」を選択して、質問A・Bのみ表示されていることを確認する
  6. 解決・未解決フィルターが「解決済み」、質問表示切り替えタブが「給付金コース」を選択して、質問Bのみ表示されていることを確認する
  7. 解決・未解決フィルターが「未解決」、質問表示切り替えタブが「給付金コース」を選択して、質問Aのみ表示されていることを確認する

質問タブの件数表示の確認

  1. /practices/200789251/questions(給付金コースのプラクティスの質問一覧)にアクセス
  2. 質問表示切り替えタブが「全て」であることを確認して、質問タブに質問(4)と表示されていることを確認する
  3. 質問表示切り替えタブが「給付金コース」を選択して、質問タブに質問(2)と表示されていることを確認する
  4. /practices/200789251/にアクセスして、質問タブに質問(4)と表示されていることを確認する

Screenshot

変更前

before

変更後

after

参考

Flakewatch Report

Flakewatch Report

Summary by CodeRabbit

  • 新機能

    • プラクティスの質問一覧に「全て/給付金コース」スコープ切替を追加し、表示対象を切り替え可能にしました。
    • 質問タブ(全て/解決済み/未解決)が現在のスコープ/フィルタを保持して遷移するよう改善しました。
    • 付与元があるプラクティスでのみスコープ切替用のピルを表示します。
  • テスト

    • スコープ×解決状態の組み合わせ表示や件数表示を検証するシステムテストを追加しました。
  • その他

    • 一覧表示の件数集計ロジックとテスト用データ(質問・正解・分類等)を更新しました。

Review Change Stack

Review App

@djkazunoko djkazunoko self-assigned this May 4, 2026
@coderabbitai

coderabbitai Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

給付金コース(grant-course)向けに、scope パラメータで質問の取得範囲を切り替える機能を追加しました。コントローラ、ヘルパー、ビュー、フィクスチャ、およびシステムテストが更新されています。

Changes

給付金コース質問スコープフィルタリング機能

Layer / File(s) Summary
Controller query logic and parameter validation
app/controllers/practices/questions_controller.rb
indexscope に応じて @practice 単体または [@practice, @practice.source_practice] を対象に Question を取得するように変更され、targetscope を検証する private メソッドを追加しました。
Helper tab count calculations
app/helpers/page_tabs/practices_helper.rb
タブの件数取得を in-memory の length から DB の count() に変更し、質問タブは practice_questions_count を用いて scope に応じた件数を返します。
View navigation UI with scope parameter
app/views/practices/questions/index.html.slim
質問タブのリンクに scope: params[:scope] を渡してスコープを保持し、@practice.source_id.present? 時に「全て/給付金コース」pill-nav を表示するようにしました。
DB and test fixtures for questions and correct answers
db/fixtures/questions.yml, db/fixtures/correct_answers.yml, test/fixtures/questions.yml, test/fixtures/correct_answers.yml
grant-course と元プラクティスに跨る質問(解決済み/未解決)と対応する正解フィクスチャを追加しました。
Fixture relationship setup and mappings
db/fixtures/practices.yml, db/fixtures/categories_practices.yml, db/fixtures/courses_categories.yml
practice113source_practice: practice23 を追加し、カテゴリ/コース関連のフィクスチャエントリを更新しました。
System tests for scope filtering and display
test/system/practice/questions_test.rb
pill-nav の表示有無、各タブ(全て/解決済み/未解決)での表示対象の切替、scope 選択時の表示限定、及び質問件数の表示を検証するシステムテストを追加しました。

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant QuestionsController
  participant Practice
  participant Question
  Client->>QuestionsController: GET /practices/:id/questions?scope=grant_course&target=solved
  QuestionsController->>QuestionsController: scope() -> 'grant_course', target() -> 'solved'
  QuestionsController->>Practice: load `@practice` and maybe source_practice
  QuestionsController->>Question: Query Question.where(practice: practices).by_target('solved')
  Question-->>QuestionsController: filtered questions
  QuestionsController-->>Client: render paginated results
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • fjordllc/bootcamp#8663: Practises::QuestionsController#index の target バリデーション・フィルタ処理に関連する変更が含まれます。

Suggested reviewers

  • komagata
  • okuramasafumi

Poem

🐰 ぴょんと広がる scope の道
給付の声も、元の声も見守るよ
タブはそのまま、表示は選べるように
テストが跳ねて、結果を確かめるよ
ぴょんと小さな祝福をどうぞ

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed 変更内容の主眼である給付金コースの質問一覧への元コース質問表示追加を的確に表しています。
Description check ✅ Passed Issue、概要、変更確認方法、Screenshotの必須項目が揃っており、内容も変更点に沿っています。
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/show-source-practice-qas-in-grant-course-practice

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented May 4, 2026

Copy link
Copy Markdown

🚀 Review App

URL: https://bootcamp-pr-9975-fvlfu45apq-an.a.run.app

Basic認証: fjord / (ステージングと同じ)
PR更新時に自動で再デプロイされます。

@djkazunoko djkazunoko force-pushed the feature/show-source-practice-qas-in-grant-course-practice branch 6 times, most recently from e007ad6 to 739f2ed Compare May 17, 2026 12:02
@djkazunoko djkazunoko marked this pull request as ready for review May 17, 2026 14:07
@github-actions github-actions Bot requested a review from okuramasafumi May 17, 2026 14:07
@djkazunoko djkazunoko removed the request for review from okuramasafumi May 17, 2026 14:08
@djkazunoko djkazunoko marked this pull request as draft May 17, 2026 14:08
@djkazunoko djkazunoko marked this pull request as ready for review May 17, 2026 14:08
@github-actions github-actions Bot requested a review from okuramasafumi May 17, 2026 14:08

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/system/practice/questions_test.rb`:
- Around line 27-29: Replace the implicit visit call with visit_with_auth so the
test does not depend on prior login state: change visit
"/practices/#{practices(:practice1).id}/questions" to visit_with_auth
"/practices/#{practices(:practice1).id}/questions", user:
users(:your_fixture_user) (use the appropriate fixture or factory for an
authenticated user in this test); keep the subsequent assert_no_selector lines
unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f0510638-a3c8-4e00-a011-4b26f10a6824

📥 Commits

Reviewing files that changed from the base of the PR and between 1906c27 and 3af6b7d.

📒 Files selected for processing (11)
  • app/controllers/practices/questions_controller.rb
  • app/helpers/page_tabs/practices_helper.rb
  • app/views/practices/questions/index.html.slim
  • db/fixtures/categories_practices.yml
  • db/fixtures/correct_answers.yml
  • db/fixtures/courses_categories.yml
  • db/fixtures/practices.yml
  • db/fixtures/questions.yml
  • test/fixtures/correct_answers.yml
  • test/fixtures/questions.yml
  • test/system/practice/questions_test.rb
💤 Files with no reviewable changes (1)
  • db/fixtures/practices.yml

Comment thread test/system/practice/questions_test.rb Outdated
@djkazunoko djkazunoko force-pushed the feature/show-source-practice-qas-in-grant-course-practice branch from 3af6b7d to 8f4f7c1 Compare May 18, 2026 04:19
@djkazunoko djkazunoko requested a review from koguchi-e May 18, 2026 05:03
@djkazunoko

Copy link
Copy Markdown
Contributor Author

@koguchi-e
お疲れ様です!
お手隙の際にこちらのレビューをお願いできますでしょうか?
(急ぎではないのでご対応はいつでも大丈夫です)

@djkazunoko djkazunoko changed the title 給付金コースのプラクティスの関連Q&A一覧に元コースの関連Q&Aも表示 給付金コースのプラクティスの質問一覧に元コースのプラクティスの質問も表示できるようにした May 18, 2026
@koguchi-e

Copy link
Copy Markdown
Contributor

@djkazunoko
ご依頼ありがとうございます!
一両日中に対応させていただきます!
引き続きよろしくお願いいたします🙏

@djkazunoko

Copy link
Copy Markdown
Contributor Author

@koguchi-e
#9733 がマージされて、コンフリクトが発生したので解消までしばしお待ちください🙇‍♂️

@koguchi-e

Copy link
Copy Markdown
Contributor

@djkazunoko
ご連絡ありがとうございます。
こちら承知しました~🫡

@djkazunoko djkazunoko force-pushed the feature/show-source-practice-qas-in-grant-course-practice branch from 8f4f7c1 to 4afac36 Compare May 19, 2026 12:38

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@db/fixtures/categories_practices.yml`:
- Around line 360-373: Update the YAML fixture entry for
categories_practice113_1 (practice: practice113, category: category24) so its
position value is 1 instead of 16 to comply with acts_as_list scope: :category
ordering (each category's positions must start at 1); simply change the position
for categories_practice113_1 to 1.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f13a9cbe-65d4-42ac-ae86-975ebe6a04a4

📥 Commits

Reviewing files that changed from the base of the PR and between 8f4f7c1 and 4afac36.

📒 Files selected for processing (11)
  • app/controllers/practices/questions_controller.rb
  • app/helpers/page_tabs/practices_helper.rb
  • app/views/practices/questions/index.html.slim
  • db/fixtures/categories_practices.yml
  • db/fixtures/correct_answers.yml
  • db/fixtures/courses_categories.yml
  • db/fixtures/practices.yml
  • db/fixtures/questions.yml
  • test/fixtures/correct_answers.yml
  • test/fixtures/questions.yml
  • test/system/practice/questions_test.rb
✅ Files skipped from review due to trivial changes (1)
  • test/fixtures/correct_answers.yml
🚧 Files skipped from review as they are similar to previous changes (9)
  • db/fixtures/questions.yml
  • db/fixtures/courses_categories.yml
  • app/controllers/practices/questions_controller.rb
  • test/fixtures/questions.yml
  • app/views/practices/questions/index.html.slim
  • db/fixtures/correct_answers.yml
  • test/system/practice/questions_test.rb
  • app/helpers/page_tabs/practices_helper.rb
  • db/fixtures/practices.yml

Comment thread db/fixtures/categories_practices.yml Outdated
@djkazunoko djkazunoko force-pushed the feature/show-source-practice-qas-in-grant-course-practice branch from 4afac36 to 5e8032f Compare May 19, 2026 13:59

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@db/fixtures/categories_practices.yml`:
- Around line 320-358: The fixtures for category6 have duplicated positions:
categories_practice65 and categories_practice69 both use position: 14, and
categories_practice67 and categories_practice71 both use position: 15, causing
non-unique ordering; update the position values for the entries
(categories_practice65, categories_practice69, categories_practice67,
categories_practice71) so that within category6 each record has a unique
sequential position (e.g., renumber them to a continuous, non-conflicting
sequence) and keep other practice/category associations unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bce047e7-5a7b-4471-971a-dbbd55283f65

📥 Commits

Reviewing files that changed from the base of the PR and between 4afac36 and 5e8032f.

📒 Files selected for processing (9)
  • app/controllers/practices/questions_controller.rb
  • app/helpers/page_tabs/practices_helper.rb
  • app/views/practices/questions/index.html.slim
  • db/fixtures/categories_practices.yml
  • db/fixtures/correct_answers.yml
  • db/fixtures/questions.yml
  • test/fixtures/correct_answers.yml
  • test/fixtures/questions.yml
  • test/system/practice/questions_test.rb
✅ Files skipped from review due to trivial changes (1)
  • test/fixtures/correct_answers.yml
🚧 Files skipped from review as they are similar to previous changes (6)
  • test/fixtures/questions.yml
  • db/fixtures/questions.yml
  • app/controllers/practices/questions_controller.rb
  • db/fixtures/correct_answers.yml
  • app/views/practices/questions/index.html.slim
  • test/system/practice/questions_test.rb

Comment thread db/fixtures/categories_practices.yml
@djkazunoko djkazunoko force-pushed the feature/show-source-practice-qas-in-grant-course-practice branch from 5e8032f to 08c0d10 Compare May 20, 2026 00:05
@djkazunoko

Copy link
Copy Markdown
Contributor Author

@koguchi-e
コンフリクト解消しましたので、再度レビューお願いします〜

@koguchi-e

Copy link
Copy Markdown
Contributor

@djkazunoko
お疲れ様です。

動作確認したところ、feature/show-source-practice-qas-in-grant-course-practice ブランチでのみ Rails サーバーが起動できませんでした。

確認したところ、以下の2点が main ブランチとズレがありました。

app/assets/javascripts/application.js

//= require select2/dist/js/select2.full.js

こちらは main ブランチでは削除されているようでした。

app/javascript/js-select2.js

こちらは main ブランチではファイル自体が存在しない状態でした。

また、//= require select2/dist/js/select2.full.js を一時的に外すと Rails サーバー自体は起動できました。

そのため、こちらのブランチに main の変更が一部取り込まれていない可能性があるかもしれないと思いました。

お手数ですが、ご確認をお願いいたします。

@djkazunoko

djkazunoko commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

ご確認ありがとうございます。

こちらのローカルでfeature/show-source-practice-qas-in-grant-course-practiceブランチを確認したところ、以下の状態でした。

  • app/assets/javascripts/application.js//= require select2/dist/js/select2.full.js の記述は存在しない
  • app/javascript/js-select2.js は存在しない

また、origin/feature/show-source-practice-qas-in-grant-course-practice と比較しても、これらのファイルに差分はありませんでした。

❯ git log --oneline -5
08c0d10dd (HEAD -> feature/show-source-practice-qas-in-grant-course-practice, origin/feature/show-source-practice-qas-in-grant-course-practice) categoryごとのpracticeのpositionが重複・欠番・不自然な値になっていたため修正
0e865773d ページタブの件数取得をlengthからcountに変更して不要なロードを防ぐ
4aec06be8 Practices::QuestionsControllerのparams処理をリファクタリング
3670a983a 質問タブの件数表示を表示範囲に応じて変更する
d5b710efa 給付金コースの質問一覧に元コースの質問を表示

❯ git diff origin/main...HEAD -- app/assets/javascripts/application.js
(何も表示されない)
❯ git diff origin/main...HEAD -- app/javascript/js-select2.js
(何も表示されない)

❯ git show HEAD:app/assets/javascripts/application.js
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require activestorage


❯ git show HEAD:app/javascript/js-select2.js
fatal: path 'app/javascript/js-select2.js' does not exist in 'HEAD'

日報 に記載されていたgit blame の結果を見ると、Not Committed Yet と表示されている箇所があったため、@koguchi-e さんのローカル環境の状態が影響しているのかなと思いました。

お手数ですが、git statusでローカルの状態をご確認いただいた上で、

git switch feature/show-source-practice-qas-in-grant-course-practice
git pull origin feature/show-source-practice-qas-in-grant-course-practice

を実行して、再度ご確認いただけますでしょうか。

また、今回のような日報に記載されている再現ログやエラーログは GitHub のコメントにも記載いただけると、状況の把握や調査がしやすくて助かります 🙏

@koguchi-e

Copy link
Copy Markdown
Contributor

@djkazunoko
ご確認ありがとうございます。
こちらでも改めて状況を整理しました。

確認したところ、当時の状態が正しく保存できているわけではないため推測となりますが、レビュー対象ブランチの状態を十分確認できていなかった可能性がございます。

git checkout main
git pull --rebase origin main
git checkout feature/show-source-practice-qas-in-grant-course-practice

を実行しており、当時はレビュー対象ブランチも最新の状態で確認できている認識でした。

しかし後から調べたところ、git pull --rebase origin main によって更新されるのは main ブランチの内容であり、レビュー対象のローカルブランチ自体が GitHub 上の状態と一致していることまでは確認できていませんでした。

そのため、私のローカル環境の状態が影響していた可能性があります。大変失礼いたしました。
また、今後は再現手順やエラーログについても GitHub のコメントに併せて記載するようにします。

ご確認いただいた内容については問題ないことを確認できましたので、Approve させていただきました。

@djkazunoko

Copy link
Copy Markdown
Contributor Author

@koguchi-e
解決したようでよかったです!レビューしていただきありがとうございました!

@djkazunoko

Copy link
Copy Markdown
Contributor Author

@okuramasafumi
お疲れ様です!
受講生レビューが完了したため、こちらのレビューをお願いします!

params[:target] if %w[solved not_solved].include?(params[:target])
end

def scope

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

未使用に見えます。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご確認ありがとうございます。
使用はされていましたが、メソッド名が分かりにくかったため、selected_targetselected_scope に変更しました。ae8b17e

.page(params[:page])
practices =
if scope == 'grant_course'
@practice

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

別の箇所では配列にしているので(そのほうが同じ配列になるので)、[@practice]にすることを検討できそうです。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご確認ありがとうございます。
返り値を配列に統一しました。711bcce
併せて question_practices メソッドに切り出して処理を整理しました。461aeb3

djkazunoko added 12 commits July 7, 2026 16:07
本番環境ではlib/tasks/bootcamp.rakeのcopy_practicesタスクにより新たなカテゴリが作成され、作成されたカテゴリが給付金コースに紐づけられる。

他のコースに紐づいている既存カテゴリを給付金コースに紐付けることをやめて、新たに作成したカテゴリを給付金コースに紐づけることで本番環境と統一した。
通し番号の方がfixture名の規則が分かりやすく、追加時にも連番で管理しやすいため。
- 「全て」では元コースを含む合算件数を表示
- 「給付金コース」では給付金コースのみの件数を表示
- 質問ページ以外では合算件数を表示
lengthでは SELECT * によりレコード全件をロードしていたが、countを使うことで SELECT COUNT(*) による件数取得のみに変更
@djkazunoko djkazunoko force-pushed the feature/show-source-practice-qas-in-grant-course-practice branch from 08c0d10 to 461aeb3 Compare July 7, 2026 07:49
end

def question_practices
if selected_scope == 'grant_course'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selected_scopeparams[:scope] if %w[grant_course].include?(params[:scope])となっていますが、その返り値を考えると、if条件が成立するのはparams[:scope] == 'grant_course'の場合だけですので、条件成立時に'grant_course'、不成立時にnilになります。

さて、Rubyではifの後ろはfalsenil以外は全てtrueとして扱われます。つまり、if 'nantoka'と書くことができます。
ということは、if selected_scope == 'grant_course'if selected_scopeと同じ動きをします。
もしこのように書くとした場合、今度はselected_scopeの命名に違和感が出てきます。というのは、内容としては「給付金コースなら」というものであるのに、if selected_scopeの字面だと「選択されたコースがあるなら」という意味になってしまうからです。今の意味内容に寄せるなら、grant_course?くらいの名前でもいいかもしれません。
ただし、これは今時点の実装がそうなっているというだけかもしれません。将来的にselected_scopeの実装が変わるなら、今のままの命名でむしろ正しいかもしれません。そのときには、if selected_scope == 'grant_course'と書くことになる可能性も高いので、実装も今のままでよいことになります。


長々書いてしまったのですが、これは結局「将来のことをどこまで見越して設計するか」という話の一例です。自分はその点についての知識がないため、判断ができません。そのように判断が難しい場合は、ひとまず一番単純なものを作っておくことが正しいとされています(You ain't gonna need it, YAGNIと呼ばれます)。
このコメントはヒントとして捉えてもらえるといいかと思います。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご確認ありがとうございます!

おっしゃる通りgrant_course しか返さないのに selected_scope という命名は違和感があると感じました。

またparams[:scope] if %w[grant_course].include?(params[:scope])の処理自体も、現状では不要だと思いました。(selected_target のように複数の選択肢を扱う場合は有効ですが、今回は grant_course の1種類しかないため)

そのため、selected_scope メソッドを削除し、question_practices 内で params[:scope] == 'grant_course' を直接判定するように修正しました。8937bcd

@okuramasafumi okuramasafumi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

動作は問題なさそうなのでApproveします。一点、https://github.com/fjordllc/bootcamp/pull/9975/changes#r3564245888 にコメントを書いたので、読んでみてください。

@djkazunoko

Copy link
Copy Markdown
Contributor Author

@okuramasafumi
YAGNI の考え方や命名についてなど、とても勉強になりました。
丁寧にレビューしていただきありがとうございました!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants