Class: Kaui::AccountChildrenController

Inherits:
EngineController
  • Object
show all
Defined in:
app/controllers/kaui/account_children_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



5
6
7
8
9
10
11
12
# File 'app/controllers/kaui/account_children_controller.rb', line 5

def index
  # check that the required parent account id is provided and get its data

  @account = Kaui::Account.find_by_id(params.require(:account_id), false, false, options_for_klient)
rescue KillBillClient::API::NotFound
  flash[:error] = "Invalid parent account id supplied #{params.require(:account_id)}"
  redirect_to kaui_engine.home_path and return
end

#paginationObject

It will fetch all the children. It use the paginate to fetch all children as permitting for future exchange when killbill account/account_id/children endpoint includes offset and limit parameters.



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
# File 'app/controllers/kaui/account_children_controller.rb', line 16

def pagination
  cached_options_for_klient = options_for_klient
  searcher = lambda do |, _offset, _limit|
    Kaui::Account.find_children(, true, true, 'NONE', cached_options_for_klient)
  end

  data_extractor = lambda do |, column|
    [
      .name,
      .,
      .external_key,
      .,
      .city,
      .country
    ][column]
  end

  formatter = lambda do ||
    [
      view_context.link_to(., (.)),
      .external_key,
      view_context.humanized_money_with_symbol(.balance_to_money)
    ]
  end

  paginate searcher, data_extractor, formatter
end