Class: AdminsController::UserSearch

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Conversion, ActiveModel::MassAssignmentSecurity, ActiveModel::Validations
Defined in:
app/controllers/admins_controller.rb

Overview

TODO action needed after rails4 update

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) {|_self| ... } ⇒ UserSearch

Returns a new instance of UserSearch

Yields:

  • (_self)

Yield Parameters:


115
116
117
118
# File 'app/controllers/admins_controller.rb', line 115

def initialize(attributes={})
  assign_attributes(attributes)
  yield(self) if block_given?
end

Instance Attribute Details

#emailObject

Returns the value of attribute email


111
112
113
# File 'app/controllers/admins_controller.rb', line 111

def email
  @email
end

#guidObject

Returns the value of attribute guid


111
112
113
# File 'app/controllers/admins_controller.rb', line 111

def guid
  @guid
end

#under13Object

Returns the value of attribute under13


111
112
113
# File 'app/controllers/admins_controller.rb', line 111

def under13
  @under13
end

#usernameObject

Returns the value of attribute username


111
112
113
# File 'app/controllers/admins_controller.rb', line 111

def username
  @username
end

Instance Method Details

#any_searchfield_present?Boolean


131
132
133
134
135
# File 'app/controllers/admins_controller.rb', line 131

def any_searchfield_present?
  if %w(username email guid under13).all? { |attr| self.send(attr).blank? }
    errors.add :base, "no fields for search set"
  end
end

#assign_attributes(values, options = {}) ⇒ Object


120
121
122
123
124
# File 'app/controllers/admins_controller.rb', line 120

def assign_attributes(values, options={})
  sanitize_for_mass_assignment(values, options[:as]).each do |k, v|
    send("#{k}=", v)
  end
end

#performObject


137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'app/controllers/admins_controller.rb', line 137

def perform
  #return User.none unless valid?  # rails4
  return [] unless valid?

  users = User.arel_table
  people = Person.arel_table
  profiles = Profile.arel_table
  res = User.joins(person: :profile)
  res = res.where(users[:username].matches("%#{username}%")) unless username.blank?
  res = res.where(users[:email].matches("%#{email}%")) unless email.blank?
  res = res.where(people[:guid].matches("%#{guid}%")) unless guid.blank?
  res = res.where(profiles[:birthday].gt(Date.today-13.years)) if under13 == '1'
  res
end

#persisted?Boolean

TODO remove this once ActiveModel is included


127
128
129
# File 'app/controllers/admins_controller.rb', line 127

def persisted?
  false
end