diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index b372eb2c0..064061058 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -82,8 +82,8 @@ class SubjectsController < ApplicationController @is_creator = current_user.creator_of_subject?(@subject) # 合作团队 @members = @subject.subject_members.includes(:user) - shixun_ids = @subject.shixuns.published.pluck(:id) - challenge_ids = Challenge.where(shixun_id: shixun_ids).pluck(:id) + @shixuns = @subject.shixuns.published.pluck(:id) + challenge_ids = Challenge.where(shixun_id: @shixuns).pluck(:id) # 实训路径中的所有实训标签 @tags = ChallengeTag.where(challenge_id: challenge_ids).pluck(:name).uniq # 用户获取的实训标签 diff --git a/app/helpers/subjects_helper.rb b/app/helpers/subjects_helper.rb index f0ecd1174..c464c7a7e 100644 --- a/app/helpers/subjects_helper.rb +++ b/app/helpers/subjects_helper.rb @@ -1,10 +1,10 @@ module SubjectsHelper # 实训路径的发布状态 - def publish_status subject, is_manager, user + def publish_status subject, is_manager, user, shixuns status = -1 if is_manager - status = 0 if subject.status == 0 && subject.shixuns_count > 0 + status = 0 if subject.status == 0 && shixuns.count > 0 status = 1 if subject.status == 1 status = 2 if subject.status == 2 && user.admin? end diff --git a/app/views/subjects/show.json.jbuilder b/app/views/subjects/show.json.jbuilder index 14eb1942f..cafb08942 100644 --- a/app/views/subjects/show.json.jbuilder +++ b/app/views/subjects/show.json.jbuilder @@ -6,7 +6,7 @@ json.subject_score @subject.all_score json.member_count @subject.member_count json.allow_delete @is_creator && (@subject.status != 2 || @user.admin?) -json.publish_status publish_status(@subject, @is_creator, @user) +json.publish_status publish_status(@subject, @is_creator, @user, @shixuns) json.allow_statistics @user.manager_of_subject?(@subject) json.allow_send @user.logged? json.allow_visit @user.manager_of_subject?(@subject) || @user.admin? || @subject.status > 1