downloads desc

exceptionHandle
yanxd 12 years ago
parent d0d36186df
commit 95e77464ad

@ -31,7 +31,10 @@ class StoresController < ApplicationController
private private
def project_classification project_type=0 def project_classification project_type=0
pro_attach = Attachment.joins("LEFT JOIN projects ON attachments.container_id = projects.id").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}").
reorder("downloads").
limit(LIMIT)
doc_attach = join_tools_project "documents", project_type doc_attach = join_tools_project "documents", project_type
issue_attach = join_tools_project "issues", project_type issue_attach = join_tools_project "issues", project_type
mess_attach = []#join_tools_project "messages", project_type mess_attach = []#join_tools_project "messages", project_type
@ -39,10 +42,14 @@ class StoresController < ApplicationController
vers_attach = join_tools_project "versions", project_type vers_attach = join_tools_project "versions", project_type
wiki_attach = []#join_tools_project "wiki_pages", 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 tmp = pro_attach+doc_attach+issue_attach+mess_attach+news_attach+vers_attach+wiki_attach
tmp.sort { |a, b| b.downloads <=> a.downloads }
end end
def join_tools_project tableName, project_type=0 def join_tools_project tableName, project_type=0
Attachment.joins(str_join_table(tableName)).where("projects.project_type=#{project_type}") Attachment.joins(str_join_table(tableName)).
where("projects.project_type=#{project_type}").
reorder('downloads DESC').
limit(LIMIT)
end end
def str_join_table tableName def str_join_table tableName

@ -20,7 +20,7 @@ require "fileutils"
class Attachment < ActiveRecord::Base class Attachment < ActiveRecord::Base
belongs_to :container, :polymorphic => true belongs_to :container, :polymorphic => true
belongs_to :projects, foreign_key: 'container_id', conditions: "attachments.container_type = 'Project'" belongs_to :project, foreign_key: 'container_id', conditions: "attachments.container_type = 'Project'"
belongs_to :author, :class_name => "User", :foreign_key => "author_id" belongs_to :author, :class_name => "User", :foreign_key => "author_id"
validates_presence_of :filename, :author validates_presence_of :filename, :author

Loading…
Cancel
Save