Class: Spree::Admin::SearchController

Inherits:
BaseController show all
Defined in:
app/controllers/spree/admin/search_controller.rb

Instance Attribute Summary

Attributes included from Core::ControllerHelpers

#title

Instance Method Summary collapse

Methods included from Core::ControllerHelpers

#associate_user, included, #try_spree_current_user

Instance Method Details

#usersObject

TODO: Clean this up by moving searching out to user_class_extensions And then JSON building with something like Active Model Serializers



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/spree/admin/search_controller.rb', line 10

def users
  @users = Spree.user_class.ransack({
    :m => 'or',
    :email_start => params[:q],
    :ship_address_firstname_start => params[:q],
    :ship_address_lastname_start => params[:q],
    :bill_address_firstname_start => params[:q],
    :bill_address_lastname_start => params[:q]
  }).result.limit(params[:limit] || 100)

  respond_with(@users) do |format|
    format.json do
      address_fields = [:firstname, :lastname,
                        :address1, :address2,
                        :city, :zipcode,
                        :phone, :state_name,
                        :state_id, :country_id]
      includes = {
        :only => address_fields,
        :include => {
          :state => { :only => :name },
          :country => { :only => :name }
        }
      }

    json = @users.to_json({
      :only => [:id, :email],
      :include => { :bill_address => includes, :ship_address => includes }
    })

    render :json => json
    end
  end
end