From b51066694e24e9a1ebac373cd1080c3baff6fa8b Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Fri, 9 Oct 2015 09:06:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E9=83=A8=20=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 6 +++++- app/views/files/_tag_yun.html.erb | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 0f8330afe..057d962c8 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -134,8 +134,12 @@ class FilesController < ApplicationController if sort == "" sort = "created_on DESC" end + if keywords != "%%" resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' AND filename LIKE :like ", like: "%#{keywords}%"). reorder(sort) + else + resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' "). reorder(sort) + end #resultSet = Attachment.find_by_sql("SELECT `attachments`.* FROM `attachments` LEFT OUTER JOIN `homework_attaches` ON `attachments`.container_type = 'HomeworkAttach' AND `attachments`.container_id = `homework_attaches`.id LEFT OUTER JOIN `homework_for_courses` ON `homework_attaches`.bid_id = `homework_for_courses`.bid_id LEFT OUTER JOIN `homework_for_courses` AS H_C ON `attachments`.container_type = 'Bid' AND `attachments`.container_id = H_C.bid_id WHERE (`homework_for_courses`.course_id = 117 OR H_C.course_id = 117 OR (`attachments`.container_type = 'Course' AND `attachments`.container_id = 117)) AND `attachments`.filename LIKE '%#{keywords}%'").reorder("created_on DESC") end @@ -547,7 +551,7 @@ class FilesController < ApplicationController q = "%#{@q.strip}%" @result = find_course_attache q,@course,sort @result = visable_attachemnts @result - @result = @result.select{|attachment| attachment.tag_list.include?(@tag_name)} + @result = @result.select{|attachment| attachment.tag_list.include?(@tag_name)} unless @tag_name.blank? @searched_attach = paginateHelper @result,10 @tag_list = get_course_tag_list @course diff --git a/app/views/files/_tag_yun.html.erb b/app/views/files/_tag_yun.html.erb index 912d3b4f4..f60a5fb9e 100644 --- a/app/views/files/_tag_yun.html.erb +++ b/app/views/files/_tag_yun.html.erb @@ -1,3 +1,7 @@ + + 全部 <% unless tag_list.nil?%> <% tag_list.each do |k,v|%> <% if tag_name && tag_name == k%>