上次修改引入bug:关键字查询不到任何东西

This commit is contained in:
lizanle 2015-01-30 12:04:33 +08:00
parent e761cd5f22
commit 0232826a6e
1 changed files with 1 additions and 4 deletions

View File

@ -19,15 +19,12 @@ module SystemLogHelper
keywords = keywords.strip.split(/\s+/).collect! { |w| Regexp.new(w, 'i') }
# 一条记录应该匹配每个关键字 log =~ r 是对log记录进行判断是否符合r的正则表达式
logs = logs.find_all do |log|
keywords.all? { |r| log =~ r }
keywords.all? { |r| log =~ r && !(log =~ Regexp.new("SystemLogController#",'i')) }
end
#用Kaminari分页
logs = Kaminari.paginate_array(logs).page(page).per(per).collect! { |log| parse(log) }
#将分页后的记录的搜索结果添加样式,样式中的\0是给给r占位置的。
logs.collect! do |log|
if log =~ Regexp.new("SystemLogController",'i')
log = ""
end
keywords.each { |r| log.gsub!(r, '<span class="search_results">\0</span>') }
log
end