Class: ClientsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/clients_controller.rb

Overview

manage a clients’list

Instance Method Summary collapse

Methods inherited from ApplicationController

#check_lang, #prepare_attached_docs_request

Instance Method Details

#indexObject

return a json list of all clients
if route is clients?melfrag=some_text, return a json list of clients with emails containing some_text



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/clients_controller.rb', line 11

def index
  if melfrag=params[:melfrag]
    if Rails.configuration.sharebox["downcase_email_search_autocomplete"]
      melfrag=melfrag.downcase
      allclients = Client.where("LOWER(mel) LIKE ?", "%#{melfrag}%")
    else
      allclients = Client.where("mel LIKE ?", "%#{melfrag}%")
    end
    results=[]
    allclients.each do |c|
      results<< {"email": c.mel,"id": c.id}
    end
  else
    results=Client.all
  end
  render json: results
end

#showObject

show a client given its id number



31
32
33
34
# File 'app/controllers/clients_controller.rb', line 31

def show
  results = Client.find_by_id(params[:id])
  render json: results
end