diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index d0bd4fb0d..54d18b65d 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -149,10 +149,13 @@ class ShixunsController < ApplicationController ## 获取顶部菜单 def menus - @repertoires = Repertoire.includes(sub_repertoires: [:tag_repertoires]).order("updated_at asc") - # respond_with @repertoires + @tag_repertoiry_ids = ShixunTagRepertoire.pluck(:tag_repertoire_id).uniq + @sub_repertoire_ids = TagRepertoire.where(id: @tag_repertoiry_ids).pluck(:sub_repertoire_id).uniq + repertoire_ids = SubRepertoire.where(id: @sub_repertoire_ids).pluck(:repertoire_id).uniq + @repertoires = Repertoire.includes(sub_repertoires: [:tag_repertoires]).where(id: repertoire_ids).order("updated_at asc") + # respond_with @repertoires - render_json + render_json end ## 实训详情 diff --git a/app/views/shixuns/menus.json.jbuilder b/app/views/shixuns/menus.json.jbuilder index 379f13e52..12676f2d0 100644 --- a/app/views/shixuns/menus.json.jbuilder +++ b/app/views/shixuns/menus.json.jbuilder @@ -17,11 +17,11 @@ json.array! @repertoires do |rep| json.id rep.id json.name rep.name json.sub_repertoires do - json.array! rep.sub_repertoires do |sub| + json.array! rep.sub_repertoires.select{ |sr| @sub_repertoire_ids.include?(sr.id)} do |sub| json.id sub.id json.name sub.name json.tags do - json.array! sub.tag_repertoires do |tag| + json.array! sub.tag_repertoires.select{|tr| @tag_repertoiry_ids.include?(tr.id) } do |tag| json.id tag.id json.name tag.name end