Code cleanup.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10802 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-11-13 22:03:42 +00:00
parent ce04c41830
commit d21cfe6bb4
1 changed files with 3 additions and 3 deletions

View File

@ -27,10 +27,10 @@ class Principal < ActiveRecord::Base
scope :active, :conditions => "#{Principal.table_name}.status = 1" scope :active, :conditions => "#{Principal.table_name}.status = 1"
scope :like, lambda {|q| scope :like, lambda {|q|
q = q.to_s
if q.blank? if q.blank?
{} where({})
else else
q = q.to_s
pattern = "%#{q}%" pattern = "%#{q}%"
sql = "LOWER(login) LIKE LOWER(:p) OR LOWER(firstname) LIKE LOWER(:p) OR LOWER(lastname) LIKE LOWER(:p) OR LOWER(mail) LIKE LOWER(:p)" sql = "LOWER(login) LIKE LOWER(:p) OR LOWER(firstname) LIKE LOWER(:p) OR LOWER(lastname) LIKE LOWER(:p) OR LOWER(mail) LIKE LOWER(:p)"
params = {:p => pattern} params = {:p => pattern}
@ -39,7 +39,7 @@ class Principal < ActiveRecord::Base
sql << " OR (LOWER(firstname) LIKE LOWER(:a) AND LOWER(lastname) LIKE LOWER(:b)) OR (LOWER(firstname) LIKE LOWER(:b) AND LOWER(lastname) LIKE LOWER(:a))" sql << " OR (LOWER(firstname) LIKE LOWER(:a) AND LOWER(lastname) LIKE LOWER(:b)) OR (LOWER(firstname) LIKE LOWER(:b) AND LOWER(lastname) LIKE LOWER(:a))"
params.merge!(:a => a, :b => b) params.merge!(:a => a, :b => b)
end end
{:conditions => [sql, params]} where(sql, params)
end end
} }