Permalink
Browse files

search by users

  • Loading branch information...
1 parent 6112625 commit 8fb0f7d629a2706b06a9c564db456bfd20a207cc @ck3g committed Apr 6, 2013
@@ -5,6 +5,8 @@ class UsersController < ApplicationController
respond_to :html
+ has_scope :term
+
def index
@users = apply_scopes(User).order(:username).page(params[:page])
end
View
@@ -28,6 +28,7 @@ class User < ActiveRecord::Base
after_create :create_profile
scope :by_login, ->(login) { where(["lower(username) = :value OR lower(email) = :value", value: login.downcase]) }
+ scope :term, ->(term) { where(["username ILIKE :value OR email ILIKE :value", value: "%#{term}%"]) }
def self.find_first_by_auth_conditions(warden_conditions)
conditions = warden_conditions.dup
@@ -0,0 +1,6 @@
+= form_tag url_for(model), class: "form-search pull-right", method: :get do
+ .input-append
+ = text_field_tag :term, params[:term], placeholder: placeholder, class: "search-query input-xlarge"
+ %button.btn
+ %i.icon-search
+ = t(:search)
@@ -1,6 +1,8 @@
.well
%h2= t(:manage_users)
+ = render 'shared/search', model: User, placeholder: t(:search_users_by_username_or_email)
+
%p= raw page_entries_info @users
%table.table.table-striped.table-condensed
View
@@ -127,3 +127,5 @@ ru:
change_password: Смена пароля
change_my_password: Сменить мой пароль
unknown_user: Неизвестный
+ search_users_by_username_or_email: Искать по имени пользователя или имейлу
+ search: Поиск

0 comments on commit 8fb0f7d

Please sign in to comment.