优化代码

dev_local_2
daiao 5 years ago
parent 4f06151277
commit ccf3aa9d2f

@ -149,7 +149,10 @@ class ShixunsController < ApplicationController
## 获取顶部菜单
def menus
@repertoires = Repertoire.includes(sub_repertoires: [:tag_repertoires]).order("updated_at asc")
@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

@ -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

Loading…
Cancel
Save