Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions app/controllers/practices/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
class Practices::QuestionsController < ApplicationController
def index
@practice = Practice.find(params[:practice_id])
allowed_targets = %w[solved not_solved].freeze
target = allowed_targets.include?(params[:target]) ? params[:target] : nil
@questions = @practice.questions
.includes(%i[correct_answer answers])
.by_target(target)
.order(created_at: :desc)
.page(params[:page])
@questions = Question.where(practice: question_practices)
.includes(%i[correct_answer answers])
.by_target(selected_target)
.order(created_at: :desc)
.page(params[:page])
@empty_message = empty_message
end

Expand All @@ -25,4 +23,16 @@ def empty_message
'質問はありません。'
end
end

def question_practices
if params[:scope] == 'grant_course'
[@practice]
else
[@practice, @practice.source_practice].compact
end
end

def selected_target
params[:target] if %w[solved not_solved].include?(params[:target])
end
end
19 changes: 16 additions & 3 deletions app/helpers/page_tabs/practices_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,26 @@ def practice_page_tabs(practice, active_tab:, include_source: nil)
tabs = []
tabs << { name: 'プラクティス', link: practice_path(practice) }
tabs << { name: '日報', link: practice_reports_path(practice), count: practice.reports_count(include_source:) }
tabs << { name: '質問', link: practice_questions_path(practice), count: practice.questions.length }
tabs << { name: 'Docs', link: practice_pages_path(practice), count: practice.pages.length }
tabs << { name: '動画', link: practice_movies_path(practice), count: practice.movies.length } if movie_available?
tabs << { name: '質問', link: practice_questions_path(practice), count: practice_questions_count(practice, active_tab:) }
tabs << { name: 'Docs', link: practice_pages_path(practice), count: practice.pages.count }
tabs << { name: '動画', link: practice_movies_path(practice), count: practice.movies.count } if movie_available?
tabs << { name: '提出物', link: practice_products_path(practice) } if practice.submission
tabs << { name: '模範解答', link: practice_submission_answer_path(practice) } if practice.submission_answer.present?
tabs << { name: 'コーディングテスト', link: practice_coding_tests_path(practice) } if practice.coding_tests.present?
render PageTabsComponent.new(tabs:, active_tab:)
end

private

def practice_questions_count(practice, active_tab:)
practices =
if active_tab == '質問' && params[:scope] == 'grant_course'
[practice]
else
[practice, practice.source_practice].compact
end

Question.where(practice: practices).count
end
end
end
16 changes: 13 additions & 3 deletions app/views/practices/questions/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,25 @@ nav.tab-nav
.container
ul.tab-nav__items
li.tab-nav__item
= link_to '全ての質問', practice_questions_path(@practice),
= link_to '全ての質問', practice_questions_path(@practice, scope: params[:scope]),
class: "tab-nav__item-link #{%w[not_solved solved].include?(params[:target]) ? '' : 'is-active'}"
li.tab-nav__item
= link_to '解決済み', practice_questions_path(@practice, target: 'solved'),
= link_to '解決済み', practice_questions_path(@practice, target: 'solved', scope: params[:scope]),
class: "tab-nav__item-link #{params[:target] == 'solved' ? 'is-active' : ''}"
li.tab-nav__item
= link_to '未解決', practice_questions_path(@practice, target: 'not_solved'),
= link_to '未解決', practice_questions_path(@practice, target: 'not_solved', scope: params[:scope]),
class: "tab-nav__item-link #{params[:target] == 'not_solved' ? 'is-active' : ''}"

- if @practice.source_id.present?
nav.pill-nav
ul.pill-nav__items
li.pill-nav__item
= link_to '全て', practice_questions_path(@practice, target: params[:target]),
class: "pill-nav__item-link #{params[:scope] == 'grant_course' ? '' : 'is-active'}"
li.pill-nav__item
= link_to '給付金コース', practice_questions_path(@practice, target: params[:target], scope: 'grant_course'),
class: "pill-nav__item-link #{params[:scope] == 'grant_course' ? 'is-active' : ''}"

.page-body
.container.is-md
= render 'questions/questions', questions: @questions, empty_message: @empty_message
36 changes: 16 additions & 20 deletions db/fixtures/categories_practices.yml
Original file line number Diff line number Diff line change
Expand Up @@ -316,63 +316,59 @@ categories_practice63:
categories_practice64:
practice: practice64
category: category10
position: 3

categories_practice111_1:
categories_practice65:
practice: practice111
category: category6
position: 14

categories_practice111_2:
categories_practice66:
practice: practice111
category: category23
position: 2

categories_practice112_1:
categories_practice67:
practice: practice112
category: category6
position: 15

categories_practice112_2:
categories_practice68:
practice: practice112
category: category23
position: 3

categories_practice65_1:
categories_practice69:
practice: practice65
category: category6
position: 14
position: 16

categories_practice65_2:
categories_practice70:
practice: practice65
category: category22
position: 2

categories_practice66_1:
categories_practice71:
practice: practice66
category: category6
position: 15
position: 17

categories_practice66_2:
categories_practice72:
practice: practice66
category: category22
position: 3
Comment thread
coderabbitai[bot] marked this conversation as resolved.

categories_practice67:
categories_practice73:
practice: practice113
category: category24
position: 16
position: 1

categories_practice68:
categories_practice74:
practice: practice114
category: category24
position: 17

categories_practice69:
practice: practice115
category: category25
position: 1

categories_practice70:
practice: practice116
categories_practice75:
practice: practice115
category: category25
position: 2
12 changes: 12 additions & 0 deletions db/fixtures/correct_answers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,15 @@ correct_answer3:
user: machida
question: question1
type: "CorrectAnswer"

correct_answer4:
description: ベストアンサーです。
user: machida
question: question57
type: "CorrectAnswer"

correct_answer5:
description: ベストアンサーです。
user: machida
question: question59
type: "CorrectAnswer"
94 changes: 2 additions & 92 deletions db/fixtures/courses_categories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,100 +135,10 @@ courses_category27:

courses_category28:
course: course5
category: category1
category: category24
position: 1

courses_category29:
course: course5
category: category2
position: 2

courses_category30:
course: course5
category: category3
position: 3

courses_category31:
course: course5
category: category4
position: 4

courses_category32:
course: course5
category: category5
position: 5

courses_category33:
course: course5
category: category6
position: 6

courses_category34:
course: course5
category: category7
position: 7

courses_category35:
course: course5
category: category8
position: 8

courses_category36:
course: course5
category: category9
position: 9

courses_category37:
course: course5
category: category10
position: 10

courses_category38:
course: course5
category: category11
position: 11

courses_category39:
course: course5
category: category12
position: 12

courses_category40:
course: course5
category: category13
position: 13

courses_category41:
course: course5
category: category14
position: 14

courses_category42:
course: course5
category: category15
position: 15

courses_category43:
course: course5
category: category16
position: 16

courses_category44:
course: course5
category: category22
position: 17

courses_category45:
course: course5
category: category23
position: 18

courses_category46:
course: course5
category: category24
position: 19

courses_category47:
course: course5
category: category25
position: 20
position: 2
8 changes: 1 addition & 7 deletions db/fixtures/practices.yml
Original file line number Diff line number Diff line change
Expand Up @@ -772,18 +772,12 @@ practice113:
source_practice: practice23

practice114:
title: "rbenvをインストールする(Reスキル)"
description: "Railsコースのプラクティスをコピーした給付金コースのプラクティスです。"
goal: "goal..."
source_practice: practice24

practice115:
title: "OS X Mountain Lionをクリーンインストールする(Reスキル)"
description: "Railsコースのプラクティスをコピーしたプラクティスです。"
goal: "goal..."
source_id: <%= ActiveRecord::FixtureSet.identify(:practice1) %>

practice116:
practice115:
title: "Terminalの基礎を覚える(Reスキル)"
description: "Railsコースのプラクティスをコピーしたプラクティスです。"
goal: "goal..."
Expand Down
32 changes: 32 additions & 0 deletions db/fixtures/questions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,35 @@ question55:
created_at: <%= Time.current - 3.month %>
updated_at: <%= Time.current - 3.month %>
published_at: <%= Time.current - 3.month %>

question56:
title: 給付金コースのプラクティスの質問
description: 給付金コースのプラクティスの質問です。
user: grant-course
practice: practice113
created_at: "2026-05-15"
published_at: "2026-05-15"

question57:
title: 給付金コースのプラクティスの質問(解決済み)
description: 解決済みです。
user: grant-course
practice: practice113
created_at: "2026-05-15"
published_at: "2026-05-15"

question58:
title: 給付金コースのコピー元プラクティスの質問
description: 給付金コースのコピー元プラクティスの質問
user: grant-course
practice: practice23
created_at: "2026-05-15"
published_at: "2026-05-15"

question59:
title: 給付金コースのコピー元プラクティスの質問(解決済み)
description: 解決済みです。
user: grant-course
practice: practice23
created_at: "2026-05-15"
published_at: "2026-05-15"
12 changes: 12 additions & 0 deletions test/fixtures/correct_answers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,15 @@ correct_answer2:
user: advijirou
question: question12
type: "CorrectAnswer"

correct_answer3:
description: ベストアンサーです。
user: machida
question: question18
type: "CorrectAnswer"

correct_answer4:
description: ベストアンサーです。
user: machida
question: question20
type: "CorrectAnswer"
Loading
Loading