From fd25c5ed300226d1416365e0de3d209554f5cb7c Mon Sep 17 00:00:00 2001 From: yanxd Date: Mon, 13 Jan 2014 20:26:40 +0800 Subject: [PATCH] ... --- app/controllers/stores_controller.rb | 36 ++++++++++++++++++---------- app/models/attachment.rb | 2 +- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/app/controllers/stores_controller.rb b/app/controllers/stores_controller.rb index 705a5e26a..cb85b39b0 100644 --- a/app/controllers/stores_controller.rb +++ b/app/controllers/stores_controller.rb @@ -9,30 +9,40 @@ class StoresController < ApplicationController # include ActsAsTaggableOn::TagsHelper LIMIT = 20 unless const_defined?(:LIMIT) def index - #Document HomeworkAttach Issue Message News Version WikiPage + @projects_attach = project_classification(0).take(LIMIT) + @courses_attach = project_classification(1).take(LIMIT) + # @projects_attach = Attachment.includes(:projects).where("projects.project_type=?", 0). + # reorder("#{Attachment.table_name}.created_on DESC"). + # limit(LIMIT) - @projects_attach = Attachment.includes(:attach_project).where("projects.project_type=?", 0). - reorder("#{Attachment.table_name}.created_on DESC"). - limit(LIMIT) - - @courses_attach = Attachment.includes(:attach_project).where("projects.project_type=?", 1). - reorder("#{Attachment.table_name}.created_on DESC"). - limit(LIMIT) + # @courses_attach = Attachment.includes(:projects).where("projects.project_type=?", 1). + # reorder("#{Attachment.table_name}.created_on DESC"). + # limit(LIMIT) @homeworks_attach = Attachment.where("container_type = 'HomeworkAttach'"). reorder("created_on DESC"). limit(LIMIT) @memos_attach = Attachment.where("container_type = 'Memo'"). reorder("created_on DESC"). limit(LIMIT) + @attach_array = Array.new + @attach_array.push(@projects_attach, @courses_attach, @homeworks_attach, @memos_attach) end private - #Document HomeworkAttach Issue Message News Version WikiPage + def project_classification project_type=0 - #Document HomeworkAttach Issue Message News Version WikiPage - doc_attach = Attachment.joins(str_join_table("documents")).where("projects.project_type=#{project_type}") - issue_attach = Attachment.joins(str_join_table("issues")).where("projects.project_type=#{project_type}") - mess_attach = Attachment.joins(str_join_table("messages")).where("projects.project_type=#{project_type}") + pro_attach = Attachment.joins("LEFT JOIN projects ON attachments.container_id = projects.id").where("projects.project_type=#{project_type}") + doc_attach = join_tools_project "documents", project_type + issue_attach = join_tools_project "issues", project_type + mess_attach = []#join_tools_project "messages", project_type + news_attach = join_tools_project "news", project_type + vers_attach = join_tools_project "versions", project_type + wiki_attach = []#join_tools_project "wiki_pages", project_type + + pro_attach+doc_attach+issue_attach+mess_attach+news_attach+vers_attach+wiki_attach + end + def join_tools_project tableName, project_type=0 + Attachment.joins(str_join_table(tableName)).where("projects.project_type=#{project_type}") end def str_join_table tableName diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 63f2ad5fa..d29b03760 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -20,7 +20,7 @@ require "fileutils" class Attachment < ActiveRecord::Base belongs_to :container, :polymorphic => true - belongs_to :attach_project, foreign_key: 'container_id', conditions: "#{Attachment.table_name}.container_type = 'Project'" + belongs_to :projects, foreign_key: 'container_id', conditions: "attachments.container_type = 'Project'" belongs_to :author, :class_name => "User", :foreign_key => "author_id" validates_presence_of :filename, :author