Class: Wco::Api::LeadsController

Inherits:
Wco::ApiController
  • Object
show all
Defined in:
app/controllers/wco/api/leads_controller.rb

Instance Method Summary collapse

Instance Method Details

#by_emailObject



7
8
9
10
# File 'app/controllers/wco/api/leads_controller.rb', line 7

def by_email
  @lead = Wco::Lead.find_or_create_by_email( params[:email] )
  render formats: [:json]
end

#indexObject

select2-leads-ajax



13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/wco/api/leads_controller.rb', line 13

def index
  authorize! :index, Wco::Lead
  @leads = Wco::Lead.all

  if params[:q].present?
    q = params[:q].downcase
    @leads = @leads.any_of(
      { email: /#{q}/i },
      { name:  /#{q}/i },
    );
  end
end

#index_hashObject



26
27
28
29
# File 'app/controllers/wco/api/leads_controller.rb', line 26

def index_hash
  authorize! :index, Wco::Lead
  @leads = Wco::Lead.find( params[:lead_ids].split(',') )
end