make search work without nickname usage

This commit is contained in:
wvengen 2013-09-20 23:18:06 +02:00
parent 17c1ee803f
commit 6d3db7636a
4 changed files with 22 additions and 12 deletions

View file

@ -56,6 +56,22 @@ class User < ActiveRecord::Base
self.settings.merge!(key, value)
end
end
# sorted by display name
def self.natural_order
# would be sensible to match ApplicationController#show_user
if FoodsoftConfig[:use_nick]
order('nick ASC')
else
order('first_name ASC, last_name ASC')
end
end
# search by (nick)name
def self.natural_search(q)
# we always use both nick and name, to make sure a user is found
where("CONCAT(first_name, CONCAT(' ', last_name)) LIKE :q OR nick LIKE :q", q: "%#{q}%")
end
def locale
settings.profile['language']