组织、项目、课程等在配置中添加成员时,对特殊字符'_'、‘/’添加转义,使能够搜索
This commit is contained in:
parent
1579a86f9f
commit
3fc988757c
|
@ -42,9 +42,9 @@ class Principal < ActiveRecord::Base
|
||||||
if q.blank?
|
if q.blank?
|
||||||
where({})
|
where({})
|
||||||
else
|
else
|
||||||
pattern = "%#{q}%"
|
pattern = "%#{q}%".gsub("/","//").gsub("_","/_")
|
||||||
# sql = %w(login firstname lastname mail).map {|column| "LOWER(#{table_name}.#{column}) LIKE LOWER(:p)"}.join(" OR ")
|
# sql = %w(login firstname lastname mail).map {|column| "LOWER(#{table_name}.#{column}) LIKE LOWER(:p)"}.join(" OR ")
|
||||||
sql= "LOWER(concat(lastname,firstname)) LIKE LOWER(:p) or LOWER(login) LIKE LOWER(:p) or LOWER(mail) LIKE LOWER(:p)"
|
sql= "LOWER(concat(lastname,firstname)) LIKE LOWER(:p) or LOWER(login) LIKE LOWER(:p) or LOWER(mail) LIKE LOWER(:p) escape '/'"
|
||||||
params = {:p => pattern}
|
params = {:p => pattern}
|
||||||
if q =~ /^(.+)\s+(.+)$/
|
if q =~ /^(.+)\s+(.+)$/
|
||||||
a, b = "#{$1}%", "#{$2}%"
|
a, b = "#{$1}%", "#{$2}%"
|
||||||
|
@ -52,7 +52,7 @@ class Principal < ActiveRecord::Base
|
||||||
sql << " OR (LOWER(#{table_name}.firstname) LIKE LOWER(:b) AND LOWER(#{table_name}.lastname) LIKE LOWER(:a))"
|
sql << " OR (LOWER(#{table_name}.firstname) LIKE LOWER(:b) AND LOWER(#{table_name}.lastname) LIKE LOWER(:a))"
|
||||||
params.merge!(:a => a, :b => b)
|
params.merge!(:a => a, :b => b)
|
||||||
end
|
end
|
||||||
where(sql, params)
|
p where(sql, params)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue