class HomeController < ApplicationController def index # banner图 images = PortalImage.where(status: true).order("position asc") @images_url = [] images.each do |image| @images_url << {path: image.link, image_url: "/images/avatars/PortalImage/#{image.id}"} end # 目录分级 repertoires = Repertoire.includes(sub_repertoires: :tag_repertoires).order("updated_at asc") @rep_list = [] repertoires.each do |rep| sub_rep_list = [] rep.sub_repertoires.each do |sub_rep| tag_rep_list = [] sub_rep.tag_repertoires.each do |tag_rep| tag_rep_list << {tag_id: tag_rep.id, tag_name: tag_rep.name} end sub_rep_list << {sub_rep_id: sub_rep.id, sub_rep_name: sub_rep.name, tag_rep_list: tag_rep_list} end @rep_list << {rep_id: rep.id, rep_name: rep.name, sub_rep_list: sub_rep_list} end @shixuns = Shixun.where(homepage_show: 1).includes(:tag_repertoires, :challenges).limit(8) @subjects = Subject.where(homepage_show: 1).includes(:shixuns, :repertoire).limit(8) @tea_users = User.where(homepage_teacher: 1).includes(:user_extension).limit(10).order("experience desc") @stu_users = User.includes(:user_extension).where(user_extensions: {identity: 1}).limit(10).order("experience desc") end def search @fuzzy_searchs = params[:keyword].split(" ").join("%") @shixuns = Shixun.where("name like ?", "%#{@fuzzy_searchs}%") @total_count = @shixuns.count end end