From 1d76d559ddddb39cc0d57f89702ed49be05a8c7b Mon Sep 17 00:00:00 2001 From: alan <547533434@qq.com> Date: Tue, 4 Nov 2014 17:06:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD<=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=90=9C=E7=B4=A2=E7=9A=84=E9=97=AE=E9=A2=98>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: alan <547533434@qq.com> --- app/controllers/users_controller.rb | 2 +- app/models/user.rb | 10 ++++++++-- app/views/users/index.html.erb | 10 ++++++++-- app/views/users/search.html.erb | 6 +++++- config/locales/zh.yml | 4 ++++ 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7e6e3d04a..5357c43ce 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -374,7 +374,7 @@ class UsersController < ApplicationController "show_changesets" => true } scope = User.logged.status(@status) - scope = scope.like(params[:name]) if params[:name].present? + scope = scope.like(params[:name],params[:search_by][:id]) if params[:name].present? @user_count = scope.count @user_pages = Paginator.new @user_count, @limit, params['page'] @user_base_tag = params[:id] ? 'base_users':'users_base' diff --git a/app/models/user.rb b/app/models/user.rb index 1e6c21c71..93356f58c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -198,13 +198,19 @@ class User < Principal } scope :sorted, lambda { order(*User.fields_for_order_statement)} - scope :like, lambda {|arg| + scope :like, lambda {|arg, type| if arg.blank? where(nil) else pattern = "%#{arg.to_s.strip.downcase}%" #where(" LOWER(concat(lastname, firstname)) LIKE :p ", :p => pattern) - where(" LOWER(login) LIKE :p ", :p => pattern) + if type == "0" + where(" LOWER(login) LIKE :p ", :p => pattern) + elsif type == "1" + where(" LOWER(concat(lastname, firstname)) LIKE :p ", :p => pattern) + else + where(" LOWER(mail) LIKE :p ", :p => pattern) + end end } diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 25c1c15c8..65e1bf2f5 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -8,8 +8,10 @@ alert("搜索条件不能为空"); return; } + $("#search_user_form").submit(); } +
@@ -21,8 +23,12 @@ -