From 21a26aba3772f1e7ba5593379f7f944ec94d72cf Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 1 Feb 2020 15:05:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=B6=E9=97=B4=E8=AF=BE=E7=A8=8B=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/weapps/subjects_controller.rb | 12 ++++++++++++ app/views/weapps/subjects/show.json.jbuilder | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 app/views/weapps/subjects/show.json.jbuilder diff --git a/app/controllers/weapps/subjects_controller.rb b/app/controllers/weapps/subjects_controller.rb index cabeb729c..a760632ae 100644 --- a/app/controllers/weapps/subjects_controller.rb +++ b/app/controllers/weapps/subjects_controller.rb @@ -1,5 +1,6 @@ class Weapps::SubjectsController < Weapps::BaseController before_action :require_login + before_action :find_subject, except: [:index] # 首页 def index @@ -8,7 +9,18 @@ class Weapps::SubjectsController < Weapps::BaseController # 详情 def show + # 合作团队 + Rails.logger.info("##########subject: #{@subject.id}") + @members = @subject.subject_members.includes(:user) + 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 + end + private + def find_subject + @subject = Subject.find(params[:id]) end end diff --git a/app/views/weapps/subjects/show.json.jbuilder b/app/views/weapps/subjects/show.json.jbuilder new file mode 100644 index 000000000..757257e82 --- /dev/null +++ b/app/views/weapps/subjects/show.json.jbuilder @@ -0,0 +1,17 @@ +json.subject do + json.name @subject.name + json.description @subject.description + json.shixuns_count @subject.shixuns_count + json.member_count @subject.member_count + json.subject_score @subject.all_score + json.learning_notes @subject.learning_notes +end + +json.team_title @subject.team_title +json.members @members do |member| + json.partial! 'subjects/subject_member', locals: { user: member.user } + json.role member.role +end + +# 技能标签 +json.tags_name @tags \ No newline at end of file